feat:Counting Algorithm #1

Merged
joy merged 1 commits from joy/dev into master 2025-10-23 13:29:55 +09:00
10 changed files with 167 additions and 0 deletions

10
.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,10 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Django PowerTools cache (generated)
/djangoPowerTools/

10
.idea/DataCompression.iml generated Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.venv" />
</content>
<orderEntry type="jdk" jdkName="uv (DataCompression)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

7
.idea/misc.xml generated Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="uv (DataCompression)" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="uv (DataCompression)" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/DataCompression.iml" filepath="$PROJECT_DIR$/.idea/DataCompression.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

42
Counting/Counting.py Normal file
View File

@ -0,0 +1,42 @@
import logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler('arithmetic_coding.log'),
logging.StreamHandler()
]
)
dict={
"A":[0,0.1],
"R":[0.1,0.2],
"I":[0.2,0.4],
"T":[0.4,0.6],
"H":[0.6,0.7],
"M":[0.7,0.8],
"E":[0.8,0.9],
"C":[0.9,1],
}
def count(word):
low = 0.0
high = 1.0
for char in word:
if char not in dict:
raise ValueError(f"Character '{char}' not in probability dictionary")
# Calculate new range
range_ = high - low
new_low = low + dict[char][0] * range_
new_high = low + dict[char][1] * range_
# Update range
low, high = new_low, new_high
print(f'({low:.15f}, {high:.15f})')
logging.info(f" Range updated to: [{new_low:.15f}, {new_high:.15f}] (width: {new_high-new_low:.15f})")
# Return the final range
return (low + high) / 2
if __name__ == "__main__":
count("ARITHMETIC")

Binary file not shown.

After

Width:  |  Height:  |  Size: 204 KiB

0
Counting/__init__.py Normal file
View File

View File

@ -0,0 +1,78 @@
2025-10-23 12:57:16,149 - INFO - Starting arithmetic coding for word: ARITHMETIC
2025-10-23 12:57:16,149 - INFO - Processing character 1/10: 'A' (range: [0.0000, 0.1000])
2025-10-23 12:57:16,149 - INFO - Range updated to: [0.000000000000000, 0.100000000000000] (width: 0.100000000000000)
2025-10-23 12:57:16,149 - INFO - Processing character 2/10: 'R' (range: [0.1000, 0.2000])
2025-10-23 12:57:16,149 - INFO - Range updated to: [0.010000000000000, 0.020000000000000] (width: 0.010000000000000)
2025-10-23 12:57:16,149 - INFO - Processing character 3/10: 'I' (range: [0.2000, 0.4000])
2025-10-23 12:57:16,149 - INFO - Range updated to: [0.012000000000000, 0.014000000000000] (width: 0.002000000000000)
2025-10-23 12:57:16,171 - INFO - Processing character 4/10: 'T' (range: [0.4000, 0.6000])
2025-10-23 12:57:16,171 - INFO - Range updated to: [0.012800000000000, 0.013200000000000] (width: 0.000400000000000)
2025-10-23 12:57:16,171 - INFO - Processing character 5/10: 'H' (range: [0.6000, 0.7000])
2025-10-23 12:57:16,171 - INFO - Range updated to: [0.013040000000000, 0.013080000000000] (width: 0.000040000000000)
2025-10-23 12:57:16,172 - INFO - Processing character 6/10: 'M' (range: [0.7000, 0.8000])
2025-10-23 12:57:16,172 - INFO - Range updated to: [0.013068000000000, 0.013072000000000] (width: 0.000004000000000)
2025-10-23 12:57:16,172 - INFO - Processing character 7/10: 'E' (range: [0.8000, 0.9000])
2025-10-23 12:57:16,172 - INFO - Range updated to: [0.013071200000000, 0.013071600000000] (width: 0.000000400000000)
2025-10-23 12:57:16,172 - INFO - Processing character 8/10: 'T' (range: [0.4000, 0.6000])
2025-10-23 12:57:16,172 - INFO - Range updated to: [0.013071360000000, 0.013071440000000] (width: 0.000000080000000)
2025-10-23 12:57:16,172 - INFO - Processing character 9/10: 'I' (range: [0.2000, 0.4000])
2025-10-23 12:57:16,172 - INFO - Range updated to: [0.013071376000000, 0.013071392000000] (width: 0.000000016000000)
2025-10-23 12:57:16,172 - INFO - Processing character 10/10: 'C' (range: [0.9000, 1.0000])
2025-10-23 12:57:16,172 - INFO - Range updated to: [0.013071390400000, 0.013071392000000] (width: 0.000000001600000)
2025-10-23 12:57:16,172 - INFO - Final result for 'ARITHMETIC': 0.013071391200000
2025-10-23 12:57:16,172 - INFO - --------------------------------------------------
2025-10-23 12:57:16,172 - INFO - Starting arithmetic coding for word: MATH
2025-10-23 12:57:16,172 - INFO - Processing character 1/4: 'M' (range: [0.7000, 0.8000])
2025-10-23 12:57:16,172 - INFO - Range updated to: [0.700000000000000, 0.800000000000000] (width: 0.100000000000000)
2025-10-23 12:57:16,172 - INFO - Processing character 2/4: 'A' (range: [0.0000, 0.1000])
2025-10-23 12:57:16,172 - INFO - Range updated to: [0.700000000000000, 0.710000000000000] (width: 0.010000000000000)
2025-10-23 12:57:16,172 - INFO - Processing character 3/4: 'T' (range: [0.4000, 0.6000])
2025-10-23 12:57:16,172 - INFO - Range updated to: [0.704000000000000, 0.706000000000000] (width: 0.002000000000000)
2025-10-23 12:57:16,172 - INFO - Processing character 4/4: 'H' (range: [0.6000, 0.7000])
2025-10-23 12:57:16,172 - INFO - Range updated to: [0.705200000000000, 0.705400000000000] (width: 0.000200000000000)
2025-10-23 12:57:16,172 - INFO - Final result for 'MATH': 0.705300000000000
2025-10-23 12:57:16,172 - INFO - --------------------------------------------------
2025-10-23 12:57:16,172 - INFO - Starting arithmetic coding for word: RICE
2025-10-23 12:57:16,172 - INFO - Processing character 1/4: 'R' (range: [0.1000, 0.2000])
2025-10-23 12:57:16,172 - INFO - Range updated to: [0.100000000000000, 0.200000000000000] (width: 0.100000000000000)
2025-10-23 12:57:16,172 - INFO - Processing character 2/4: 'I' (range: [0.2000, 0.4000])
2025-10-23 12:57:16,172 - INFO - Range updated to: [0.120000000000000, 0.140000000000000] (width: 0.020000000000000)
2025-10-23 12:57:16,172 - INFO - Processing character 3/4: 'C' (range: [0.9000, 1.0000])
2025-10-23 12:57:16,172 - INFO - Range updated to: [0.138000000000000, 0.140000000000000] (width: 0.002000000000000)
2025-10-23 12:57:16,172 - INFO - Processing character 4/4: 'E' (range: [0.8000, 0.9000])
2025-10-23 12:57:16,172 - INFO - Range updated to: [0.139600000000000, 0.139800000000000] (width: 0.000200000000000)
2025-10-23 12:57:16,172 - INFO - Final result for 'RICE': 0.139700000000000
2025-10-23 12:57:16,172 - INFO - --------------------------------------------------
2025-10-23 12:57:54,803 - INFO - Starting arithmetic coding for word: ARITHMETIC
2025-10-23 12:57:54,804 - INFO - Processing character 1/10: 'A' (range: [0.0000, 0.1000])
2025-10-23 12:57:54,804 - INFO - Range updated to: [0.000000000000000, 0.100000000000000] (width: 0.100000000000000)
2025-10-23 12:57:54,804 - INFO - Processing character 2/10: 'R' (range: [0.1000, 0.2000])
2025-10-23 12:57:54,804 - INFO - Range updated to: [0.010000000000000, 0.020000000000000] (width: 0.010000000000000)
2025-10-23 12:57:54,804 - INFO - Processing character 3/10: 'I' (range: [0.2000, 0.4000])
2025-10-23 12:57:54,804 - INFO - Range updated to: [0.012000000000000, 0.014000000000000] (width: 0.002000000000000)
2025-10-23 12:57:54,804 - INFO - Processing character 4/10: 'T' (range: [0.4000, 0.6000])
2025-10-23 12:57:54,804 - INFO - Range updated to: [0.012800000000000, 0.013200000000000] (width: 0.000400000000000)
2025-10-23 12:57:54,804 - INFO - Processing character 5/10: 'H' (range: [0.6000, 0.7000])
2025-10-23 12:57:54,804 - INFO - Range updated to: [0.013040000000000, 0.013080000000000] (width: 0.000040000000000)
2025-10-23 12:57:54,804 - INFO - Processing character 6/10: 'M' (range: [0.7000, 0.8000])
2025-10-23 12:57:54,804 - INFO - Range updated to: [0.013068000000000, 0.013072000000000] (width: 0.000004000000000)
2025-10-23 12:57:54,804 - INFO - Processing character 7/10: 'E' (range: [0.8000, 0.9000])
2025-10-23 12:57:54,804 - INFO - Range updated to: [0.013071200000000, 0.013071600000000] (width: 0.000000400000000)
2025-10-23 12:57:54,804 - INFO - Processing character 8/10: 'T' (range: [0.4000, 0.6000])
2025-10-23 12:57:54,804 - INFO - Range updated to: [0.013071360000000, 0.013071440000000] (width: 0.000000080000000)
2025-10-23 12:57:54,804 - INFO - Processing character 9/10: 'I' (range: [0.2000, 0.4000])
2025-10-23 12:57:54,804 - INFO - Range updated to: [0.013071376000000, 0.013071392000000] (width: 0.000000016000000)
2025-10-23 12:57:54,804 - INFO - Processing character 10/10: 'C' (range: [0.9000, 1.0000])
2025-10-23 12:57:54,804 - INFO - Range updated to: [0.013071390400000, 0.013071392000000] (width: 0.000000001600000)
2025-10-23 12:57:54,804 - INFO - Final result for 'ARITHMETIC': 0.013071391200000
2025-10-23 12:57:54,804 - INFO - --------------------------------------------------
2025-10-23 13:01:05,602 - INFO - Range updated to: [0.000000000000000, 0.100000000000000] (width: 0.100000000000000)
2025-10-23 13:01:05,603 - INFO - Range updated to: [0.010000000000000, 0.020000000000000] (width: 0.010000000000000)
2025-10-23 13:01:05,603 - INFO - Range updated to: [0.012000000000000, 0.014000000000000] (width: 0.002000000000000)
2025-10-23 13:01:05,603 - INFO - Range updated to: [0.012800000000000, 0.013200000000000] (width: 0.000400000000000)
2025-10-23 13:01:05,603 - INFO - Range updated to: [0.013040000000000, 0.013080000000000] (width: 0.000040000000000)
2025-10-23 13:01:05,603 - INFO - Range updated to: [0.013068000000000, 0.013072000000000] (width: 0.000004000000000)
2025-10-23 13:01:05,603 - INFO - Range updated to: [0.013071200000000, 0.013071600000000] (width: 0.000000400000000)
2025-10-23 13:01:05,603 - INFO - Range updated to: [0.013071360000000, 0.013071440000000] (width: 0.000000080000000)
2025-10-23 13:01:05,603 - INFO - Range updated to: [0.013071376000000, 0.013071392000000] (width: 0.000000016000000)
2025-10-23 13:01:05,603 - INFO - Range updated to: [0.013071390400000, 0.013071392000000] (width: 0.000000001600000)