Commit 08c8883b authored by npedot's avatar npedot
Browse files

changes test folder to root

parent bce8227b
......@@ -29,7 +29,7 @@ def simple_net():
def net(x):
a = tf.sigmoid(tf.reduce_sum(
tf.multiply(tf.matmul(x, N), x), axis=1))
print("A SHAPE: {}".format(a.shape))
#print("A SHAPE: {}".format(a.shape))
return a
return net
......@@ -53,10 +53,10 @@ ltnw.axiom('forall x:(Worker(x) -> Adult(x))')
# Constraints
ltnw.axiom('~Adult(a)')
#ltnw.axiom('Worker(a)')
#ltnw.axiom('~Adult(a)')
ltnw.axiom('Worker(a)')
#ltnw.axiom('~Married(a)')
#ltnw.axiom('Worker(b)')
#ltnw.axiom('~Worker(b)')
# *** TRAIN
......
......@@ -15,6 +15,7 @@ EMBEDDING_SIZE = 6
ltnw.constant('a',min_value=[1.,2.,3.,0.,1.,2.],max_value=[1.,2.,3.,100.,1.,2.])
ltnw.constant('b',min_value=[4.,5.,6.,0.,1.,2.],max_value=[4.,5.,6.,100.,1.,2.])
ltnw.constant('c',min_value=[4.,5.,6.,0.,1.,2.],max_value=[4.,5.,6.,100.,1.,2.])
#ltnw.constant('d',min_value=[4.,5.,6.,0.,1.,2.],max_value=[4.,5.,6.,100.,1.,2.])
ltnw.constant('e',min_value=[4.,5.,6.,0.,1.,2.],max_value=[4.,5.,6.,100.,1.,2.])
ltnw.constant('f',min_value=[4.,5.,6.,0.,1.,2.],max_value=[4.,5.,6.,100.,1.,2.])
ltnw.constant('g',min_value=[4.,5.,6.,0.,1.,2.],max_value=[4.,5.,6.,100.,1.,2.])
......@@ -25,13 +26,22 @@ print(ltnw.CONSTANTS)
def _close_eta(x,y):
return 1-tf.abs(x-y)/100.
def _adult(x):
age = x[:,3]
print("AGE============")
if age>=18:
return 1.
else:
0.
ltnw.function('eta',4,fun_definition=lambda x:x[:,3])
ltnw.predicate("close_eta",2,_close_eta)
ltnw.predicate("adult",1,_adult)
ltnw.axiom("close_eta(eta(a),ten)")
ltnw.axiom("close_eta(eta(b),twenty)")
ltnw.axiom("close_eta(eta(b),eta(c))")
#ltnw.axiom("adult(eta(e))")
def simple_net():
N = tf.Variable(tf.random_normal((EMBEDDING_SIZE, EMBEDDING_SIZE),
......@@ -40,26 +50,27 @@ def simple_net():
def net(x):
a = tf.sigmoid(tf.reduce_sum(
tf.multiply(tf.matmul(x, N), x), axis=1))
print("A SHAPE: {}".format(a.shape))
#print("A SHAPE: {}".format(a.shape))
return a
return net
ltnw.predicate("Adult", EMBEDDING_SIZE, pred_definition=simple_net())
ltnw.predicate("Married", EMBEDDING_SIZE, pred_definition=simple_net())
ltnw.predicate("Worker", EMBEDDING_SIZE, pred_definition=simple_net())
#ltnw.predicate("Married", EMBEDDING_SIZE, pred_definition=simple_net())
#ltnw.predicate("Worker", EMBEDDING_SIZE, pred_definition=simple_net())
constants = list('abcefg')
ltnw.variable('z', tf.concat(
[ltnw.CONSTANTS[c] for c in constants], axis=0))
ltnw.axiom('forall z:(Worker(z) -> Adult(z))')
ltnw.axiom('forall z:(Married(z) -> Adult(z))')
#ltnw.axiom('forall z:(close_eta(z,twenty) -> Adult(z))')
#ltnw.axiom('forall z:(Worker(z) -> Adult(z))')
#ltnw.axiom('forall z:(Married(z) -> Adult(z))')
ltnw.axiom('forall z:(adult(z) -> Adult(z))')
ltnw.axiom('~Adult(a)')
ltnw.axiom('Adult(b)')
#ltnw.axiom('~Adult(a)')
#ltnw.axiom('Adult(b)')
#ltnw.axiom('Worker(d)')
ltnw.initialize_knowledgebase(optimizer=tf.train.RMSPropOptimizer(learning_rate=.01),
......@@ -70,8 +81,10 @@ ltnw.train(max_epochs=20000)
print("eta(a)",ltnw.ask('eta(a)'))
print("eta(b)",ltnw.ask('eta(b)'))
print("eta(c)",ltnw.ask('eta(c)'))
print("eta(d)",ltnw.ask('eta(e)'))
print("adult(a)",ltnw.ask('Adult(a)'))
print("adult(b)",ltnw.ask('Adult(b)'))
print("adult(c)",ltnw.ask('Adult(c)'))
print("adult(d)",ltnw.ask('Adult(e)'))
......@@ -94,7 +94,6 @@ def fix_csv(filepath, filename, working_columns, cells_to_fix,
ldb.write_db(filepath, df1)
# creare il file formule di mutua esclusione sui predicati.
# TO DO
ldb_write.write_formulas(filepath, column_key_enum)
ldb.atomize_matrix(filepath)
......
......@@ -19,6 +19,9 @@ ___[...] Initilizing elements.
========== variable range 0
x
['t1' 't2']
A(t1)
B(t1)
A(t2)
___[...] Initialized.
___[...] Initializing knowledgebase.
___[...] Training.
......@@ -27,10 +30,10 @@ ___[...] Trained.
>>> ldb.ask_atoms() #doctest: +ELLIPSIS
for t1
_TRUE A(t1) [...]
_TRUE B(t1) [...]
_FALSE ERR(t1) [...]
('_TRUE A(t1)', array([...], dtype=float32))
('_TRUE B(t1)', array([...], dtype=float32))
('_FALSE ERR(t1)', array([...], dtype=float32))
for t2
_TRUE A(t2) [...]
_TRUE B(t2) [...]
_FALSE ERR(t2) [...]
('_TRUE A(t2)', array([...], dtype=float32))
('_TRUE B(t2)', array([...], dtype=float32))
('_FALSE ERR(t2)', array([...], dtype=float32))
......@@ -19,6 +19,10 @@ ___[...] Initilizing elements.
========== variable range 0
x
['t1' 't2']
A(t1)
B(t1)
A(t2)
~B(t1)
___[...] Initialized.
___[...] Initializing knowledgebase.
___[...] Training.
......@@ -27,10 +31,10 @@ ___[...] Trained.
>>> ldb.ask_atoms() #doctest: +ELLIPSIS
for t1
_TRUE A(t1) [...]
_UNKNOWN B(t1) [...]
_... ERR(t1) [...]
('_TRUE A(t1)', array([...], dtype=float32))
('_UNKNOWN B(t1)', array([...], dtype=float32))
('_UNKNOWN ERR(t1)', array([...], dtype=float32))
for t2
_TRUE A(t2) [...]
_... B(t2) [...]
_... ERR(t2) [...]
('_TRUE A(t2)', array([...], dtype=float32))
('_... B(t2)', array([...], dtype=float32))
('_... ERR(t2)', array([...], dtype=float32))
......@@ -164,6 +164,13 @@ The test result for B (t2) will be true with rapid convergence, as there is no c
Case study: [test_ldb_basic](../docker/docker-ldb/ldb/test/test_basic.txt)
### Minimal example of inconsistency
Starting from the previous categorical case if we add a description that contradicts a constraint, optimization will end by timeout and not by minimizing the distances of the constraints, leaving the value space in an unsecured configuration to satisfy all constraints.
Case study: [test_ldb_basic_contradiction](../docker/docker-ldb/ldb/test/test_basic_contradiction.txt)
### Minimal categorical example
To translate a categorical feature, the membership of the category must be specified for each value.
......@@ -175,13 +182,6 @@ assumed by other parameters, eg worker, adult
Case study: [test_ldb_category](../docker/docker-ldb/ldb/sample/basic_category.py)
### Minimal example of inconsistency
Starting from the previous categorical case if we add a description that contradicts a constraint, optimization will end by timeout and not by minimizing the distances of the constraints, leaving the value space in an unsecured configuration to satisfy all constraints.
Case study: [test_ldb_basic_contradiction](../docker/docker-ldb/ldb/test/test_basic_contradiction.txt)
### Minimal numerical example
We translate a simple archive that describes a numerical feature.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment