Commit a27f2e31 by josd

### modalities producing Turtle or N3

parent 8880810c
 from sympy import * from sympy import * x = Symbol('x') x = Symbol('x') y = integrate(exp(-x**2), (x, -oo, oo)) print('PREFIX : ') print('PREFIX : ') print('') print('') print('"exp(-x**2), (x, -oo, oo)" :integrate "%s".' % (y)) print('"integrate(exp(-x**2), (x, -oo, oo))" :integral "%s".' % (integrate(exp(-x**2), (x, -oo, oo))))
 PREFIX : PREFIX : "exp(-x**2), (x, -oo, oo)" :integrate "sqrt(pi)". "integrate(exp(-x**2), (x, -oo, oo))" :integral "sqrt(pi)".
 ... @@ -14,7 +14,7 @@ def calc_easter(year): ... @@ -14,7 +14,7 @@ def calc_easter(year): return date(year, month, day) return date(year, month, day) print('PREFIX xsd: ') print('PREFIX xsd: ') print('PREFIX : ') print('PREFIX : ') print('') print('') print('2019 :easter "%s"^^xsd:date.' % (calc_easter(2019))) print('2019 :easter "%s"^^xsd:date.' % (calc_easter(2019))) print('2020 :easter "%s"^^xsd:date.' % (calc_easter(2020))) print('2020 :easter "%s"^^xsd:date.' % (calc_easter(2020))) ... ...
 ... @@ -4,8 +4,8 @@ def fib(n, c={0:1, 1:1}): ... @@ -4,8 +4,8 @@ def fib(n, c={0:1, 1:1}): c[n] = fib(x-1) * fib(n-x-1) + fib(x) * fib(n-x) c[n] = fib(x-1) * fib(n-x-1) + fib(x) * fib(n-x) return c[n] return c[n] y = fib(91) print('PREFIX : ') print('PREFIX : ') print('') print('') print('91 :fib "%d".' % (y)) print('0 :fib "%d".' % (fib(0))) print('91 :fib "%d".' % (fib(91))) print('283 :fib "%d".' % (fib(283)))
 PREFIX : PREFIX : 0 :fib "1". 91 :fib "7540113804746346429". 91 :fib "7540113804746346429". 283 :fib "100694286476841731898333719576864360661213863366454327287613".
 === Transformer for wind turbines === This is about predicting wind turbine power from wind turbine observations. The run.sh script is doing the following: - generate data for the turbine model training - train the turbine model - export the turbine model - test the exported turbine model using the test.sh script
 from . import observation_prediction_turbine
 #!/usr/bin/env python3 import sys # predictions with open('test_turbine.prediction', 'r') as f: p = [r.split()[1] for r in f] # expectations with open('test_turbine.expectation', 'r') as f: e = [r.split()[1] for r in f] # beliefs with open('test_turbine.prediction', 'r') as f: b = [float(r.split()[-1]) for r in f] # belief treshold t = 0.0 if len(sys.argv) > 1: t = eval(sys.argv[1]) # metrics r = sum([1 if i == j and k >= t else 0 for i, j, k in zip(p, e, b)]) w = sum([1 if i != j and k >= t else 0 for i, j, k in zip(p, e, b)]) e = sum([1 if k < t else 0 for i, j, k in zip(p, e, b)]) print("right_predictions: %d" % (r)) print("wrong_predictions: %d" % (w)) print("excl_predictions: %d" % (e)) print("accuracy: %.2f" % (r/(r+w) if r+w != 0 else float('NaN'))) print("excl_rate: %.2f" % (e/(r+w+e) if r+w+e != 0 else float('NaN')))
File deleted
 #!/usr/bin/env python3 import random import sys from tensor2tensor.data_generators import problem from tensor2tensor.data_generators import text_problems from tensor2tensor.utils import registry @registry.register_problem class ObservationPredictionTurbine(text_problems.Text2TextProblem): """Processing Observations into Propositions for wind turbines.""" @property def approx_vocab_size(self): return 2**14 # ~16k @property def is_generate_per_split(self): # generate_data will shard the data into TRAIN and EVAL for us. return False @property def dataset_splits(self): """Splits of data to produce and number of output shards for each.""" return [{ "split": problem.DatasetSplit.TRAIN, "shards": 9, }, { "split": problem.DatasetSplit.EVAL, "shards": 1, }] def generate_samples(self, data_dir, tmp_dir, dataset_split): del data_dir del tmp_dir del dataset_split for n in range(100000): # wind turbine size factor size_factor = random.randint(1, 10) # wind speed wind_speed = max(0, int(random.gauss(25, 15))) # wind turbine power turbine_power = int(0.01*size_factor*wind_speed**3) yield { "inputs": "TURBINE_SIZE_FACTOR " + repr(size_factor) + " WIND_SPEED_KM/H " + repr(wind_speed), "targets": "TURBINE_POWER_KW " + repr(turbine_power) } if __name__ == '__main__': what = "inputs" if len(sys.argv) > 1: what = sys.argv[1] gen = ObservationPredictionDice.generate_samples(None, None, None, None) for i in gen: print(i.get(what))