Comments (2)
Thank you for reporting! Could you expand on your use case? The point of any source coding encoder is to convert a message (i.e., a sequence of symbols) to a bit string. The message can be of arbitrary length. In particular, when using a symbol code like Huffman coding, there's nothing wrong with encoding a message that consists of only a single symbol:
import constriction
import numpy as np
def single_code_word(symbol, code_book):
encoder = constriction.symbol.QueueEncoder()
encoder.encode_symbol(symbol, code_book)
code_word, length = encoder.get_compressed()
return f'{code_word[0]:0{length}b}'[::-1] # works for code words of length <=32
probabilities = np.array([0.1, 0.2, 0.3, 0.4])
code_book = constriction.symbol.huffman.EncoderHuffmanTree(probabilities)
print({symbol: single_code_word(symbol, code_book) for symbol in range(4)})
Are you looking for a more convenient way to do this? If so, I'd be curious which of the following best describes your use case:
- being able to call
dict(tree)
wheretree
is anEncoderHuffmanTree
, and getting a dictionary that maps symbols to some representations of bit strings (like in the above example); - having a method on
EncoderHuffmanTree
that takes a symbol as argument and outputs some representation of this symbol's code word; - having a simple way to summarize an
EncoderHuffmanTree
in a human-readable string for debugging; or - something else?
from constriction.
Closing this for now because it's not actionable without further information. As mentioned in my last comment, the specific requested feature already exists, and while it is very well possible that the existing solution may not be suitable for all use cases, further information is needed to clarify what exactly is missing. Without clarification of the intended use case, any attempt from my side to guess and address the underlying issue would likely run into the XY problem.
Please feel free to reopen if you can clarify the broader picture of what you're trying to achieve.
from constriction.
Related Issues (10)
- ImportError: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.29' not found HOT 2
- Creating a categorical distribution sometimes fails to converge HOT 1
- assertions not supported for parameter cdf in constriction.stream.model.CustomModel HOT 1
- Vectorize cdf query of custom model HOT 1
- Different behavior on amd64 and arm HOT 8
- Relax minimal numpy version, if possible HOT 6
- Encoding int8/unit8 streams of symbols HOT 5
- List `LICENSE.html` in `RECORD` file of python wheels HOT 1
- TANS with separate probability HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from constriction.