changeset 0:e93aac1287c0

Initial commit
author Lewin Bormann <lbo@spheniscida.de>
date Thu, 24 Dec 2020 08:54:24 +0100
parents
children 59ba73797553
files .hgignore bin2dec.py
diffstat 2 files changed, 32 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore	Thu Dec 24 08:54:24 2020 +0100
@@ -0,0 +1,1 @@
+__pycache__
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bin2dec.py	Thu Dec 24 08:54:24 2020 +0100
@@ -0,0 +1,31 @@
+#!/usr/bin/env python3
+
+from sklearn.linear_model import LinearRegression
+from sklearn.model_selection import train_test_split
+import numpy as np
+
+
+def gen_x(y):
+    x = bin(y)[2:]
+    n = 32 - len(x)
+    return [int(c) for c in '0'*n + x]
+
+
+# Generate array X of binary-character lists of random numbers
+y = np.random.randint(0, 1 << 32, size=10000)
+X = np.array([gen_x(x) for x in y])
+
+model = LinearRegression()
+model.fit(X, y)
+
+
+def bin2dec_ai(array):
+    return model.predict(array)
+
+
+def bin2dec_ai_test(n):
+    arr = gen_x(n)
+
+    actual = n
+    prediction = bin2dec_ai(np.array([arr]))
+    print('Actual: {} Predicted: {} Diff: {}'.format(actual, prediction, prediction-actual))