Skip to content

Commit

Permalink
merge changes from dev
Browse files Browse the repository at this point in the history
  • Loading branch information
maxeeem committed May 3, 2024
2 parents ba1780b + f866c4e commit 605b213
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 15 deletions.
1 change: 0 additions & 1 deletion Tests/test_RuleMap/test_sparse_lut.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from networkx.generators.random_graphs import fast_gnp_random_graph
from pynars.NARS.DataStructures._py.Link import LinkType
from pynars.NARS.RuleMap import Interface_SyllogisticRules, RuleMap
from pynars.Narsese import Budget
Expand Down
5 changes: 3 additions & 2 deletions pynars/NAL/Functions/ExtendedBooleanFunctions.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from functools import reduce
from statistics import mean
from operator import mul

Not = lambda x: (1-x)

And = lambda *x: reduce(lambda a,b: a*b, x, 1)
Or = lambda *x: 1 - reduce(lambda a,b: a*(1-b), x, 1)
And = lambda *x: reduce(mul, x, 1)
Or = lambda *x: 1 - reduce(mul, (1 - xi for xi in x), 1)
Average = lambda *x: mean(x)

def Scalar(x):
Expand Down
2 changes: 0 additions & 2 deletions pynars/NARS/RuleMap/add_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
from typing_extensions import Protocol
from collections import OrderedDict

from numpy import product

from pynars.Config import Enable
from pynars.NARS.RuleMap.Interface import Interface_CompositionalRules, Interface_SyllogisticRules, Interface_DecompositionalRules, Interface_TransformRules, Interface_ConditionalRules, Interface_TemporalRules, Interface_VariableRules
from pynars.Narsese import Copula, Task
Expand Down
11 changes: 7 additions & 4 deletions pynars/Narsese/_py/Compound.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from ordered_set import OrderedSet
from typing import Set
from pynars.utils.tools import list_contains
import numpy as np
from pynars.Global import States


Expand Down Expand Up @@ -368,9 +367,13 @@ def equal(self, o: Type['Compound']) -> bool:
set2: Iterable[Term] = o.terms - self.terms
if len(set1) == len(set2) == 0:
return True
eq_array = np.array([[term1.equal(term2)
for term2 in set2] for term1 in set1])
if np.prod(eq_array.sum(axis=0)) > 0 and np.prod(eq_array.sum(axis=1)) > 0:
# ChatGPT: directly returns the result of the logical AND condition,
# checking if all column sums and all row sums are greater than zero.
# This uses the built-in all() function to ensure every sum in each direction (column and row)
# is greater than zero. The zip(*eq_array) unpacks each row of eq_array into columns.
eq_array = [[term1.equal(term2)
for term2 in set2] for term1 in set1]
if all(sum(col) > 0 for col in zip(*eq_array)) and all(sum(row) > 0 for row in eq_array):
return True
else:
return False
Expand Down
1 change: 0 additions & 1 deletion pynars/Narsese/_py/Term.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from typing import Iterable, List, Set, Type
from enum import Enum
from pynars.utils.IndexVar import IndexVar
from numpy import prod
from ordered_set import OrderedSet
# from pynars.utils.tools import find_pos_with_pos, find_var_with_pos
from copy import copy, deepcopy
Expand Down
1 change: 0 additions & 1 deletion pynars/Narsese/_py/Truth.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from pynars.Config import Config
from typing import Type
import numpy as np

class Truth:
# analytic: Type['Truth']
Expand Down
2 changes: 0 additions & 2 deletions pynars/utils/IndexVar.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
from ordered_set import OrderedSet
from bidict import bidict

from numpy import prod

class IntVar:
def __init__(self, num: int) -> None:
self.num = int(num)
Expand Down
4 changes: 2 additions & 2 deletions pynars/utils/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def rand_seed(x: int):
import random
random.seed(x)

import numpy as np
np.random.seed(x)
# import numpy as np
# np.random.seed(x)

# if using pytorch, set its seed!
# # import torch
Expand Down
12 changes: 12 additions & 0 deletions requirements-min.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
bidict>=0.21.2
depq>=1.5.5
jstyleson>=0.0.2
pyyaml
lark==0.12.0
ordered-set>=4.0.2
sty>=1.0.0rc2
tqdm<=3.1.4
typing>=3.7.4.3
typing_extensions>=4.0.1
sparse-lut>=1.0.0
miniKanren>=1.0.3

0 comments on commit 605b213

Please sign in to comment.