compiled-knowledge 4.0.0a24__cp312-cp312-win32.whl → 4.0.0a25__cp312-cp312-win32.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of compiled-knowledge might be problematic. Click here for more details.
- ck/circuit/_circuit_cy.c +1 -1
- ck/circuit/_circuit_cy.cp312-win32.pyd +0 -0
- ck/circuit/tmp_const.py +5 -4
- ck/circuit_compiler/cython_vm_compiler/_compiler.c +152 -152
- ck/circuit_compiler/cython_vm_compiler/_compiler.cp312-win32.pyd +0 -0
- ck/circuit_compiler/support/circuit_analyser/_circuit_analyser_cy.c +1 -1
- ck/circuit_compiler/support/circuit_analyser/_circuit_analyser_cy.cp312-win32.pyd +0 -0
- ck/circuit_compiler/support/llvm_ir_function.py +4 -4
- ck/example/diamond_square.py +3 -1
- ck/example/triangle_square.py +3 -1
- ck/example/truss.py +3 -1
- ck/in_out/parse_net.py +21 -19
- ck/in_out/parser_utils.py +7 -3
- ck/pgm.py +67 -58
- ck/pgm_circuit/mpe_program.py +3 -4
- ck/pgm_circuit/pgm_circuit.py +27 -18
- ck/pgm_circuit/program_with_slotmap.py +4 -1
- ck/pgm_compiler/support/circuit_table/_circuit_table_cy.c +1 -1
- ck/pgm_compiler/support/circuit_table/_circuit_table_cy.cp312-win32.pyd +0 -0
- ck/probability/probability_space.py +10 -11
- ck/program/raw_program.py +23 -16
- ck/sampling/sampler_support.py +5 -6
- ck/utils/iter_extras.py +3 -2
- ck/utils/local_config.py +16 -8
- {compiled_knowledge-4.0.0a24.dist-info → compiled_knowledge-4.0.0a25.dist-info}/METADATA +1 -1
- {compiled_knowledge-4.0.0a24.dist-info → compiled_knowledge-4.0.0a25.dist-info}/RECORD +29 -29
- {compiled_knowledge-4.0.0a24.dist-info → compiled_knowledge-4.0.0a25.dist-info}/WHEEL +0 -0
- {compiled_knowledge-4.0.0a24.dist-info → compiled_knowledge-4.0.0a25.dist-info}/licenses/LICENSE.txt +0 -0
- {compiled_knowledge-4.0.0a24.dist-info → compiled_knowledge-4.0.0a25.dist-info}/top_level.txt +0 -0
|
Binary file
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"/O2"
|
|
14
14
|
],
|
|
15
15
|
"include_dirs": [
|
|
16
|
-
"C:\\Users\\runneradmin\\AppData\\Local\\Temp\\build-env-
|
|
16
|
+
"C:\\Users\\runneradmin\\AppData\\Local\\Temp\\build-env-8cwjzb8_\\Lib\\site-packages\\numpy\\_core\\include"
|
|
17
17
|
],
|
|
18
18
|
"name": "ck.circuit_compiler.support.circuit_analyser._circuit_analyser_cy",
|
|
19
19
|
"sources": [
|
|
Binary file
|
|
@@ -213,10 +213,10 @@ def compile_llvm_program(
|
|
|
213
213
|
Compile the given LLVM program.
|
|
214
214
|
|
|
215
215
|
Returns:
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
function
|
|
216
|
+
`engine` an LLVM execution engine, which must remain
|
|
217
|
+
in memory for the returned function to be valid,
|
|
218
|
+
|
|
219
|
+
`function` the raw Python callable for the compiled function.
|
|
220
220
|
"""
|
|
221
221
|
_init_llvm()
|
|
222
222
|
|
ck/example/diamond_square.py
CHANGED
|
@@ -8,7 +8,8 @@ class DiamondSquare(PGM):
|
|
|
8
8
|
This PGM is the 'DiamondSquare' factor graph.
|
|
9
9
|
|
|
10
10
|
The DiamondSquare is a factor graph with seven random variables (a, b, c, ..., h).
|
|
11
|
-
Binary factors are between pairs of random variables creating the pattern
|
|
11
|
+
Binary factors are between pairs of random variables creating the pattern::
|
|
12
|
+
|
|
12
13
|
b
|
|
13
14
|
/ \
|
|
14
15
|
/ \
|
|
@@ -20,6 +21,7 @@ class DiamondSquare(PGM):
|
|
|
20
21
|
\ /
|
|
21
22
|
\ /
|
|
22
23
|
g
|
|
24
|
+
|
|
23
25
|
If include_unaries then, also includes one unary factor per random variable.
|
|
24
26
|
"""
|
|
25
27
|
|
ck/example/triangle_square.py
CHANGED
|
@@ -8,12 +8,14 @@ class TriangleSquare(PGM):
|
|
|
8
8
|
This PGM is the 'TriangleSquare' factor graph.
|
|
9
9
|
|
|
10
10
|
The TriangleSquare is a factor graph with six random variables (a, b, c, ..., f).
|
|
11
|
-
Binary factors are between pairs of random variables crating the pattern
|
|
11
|
+
Binary factors are between pairs of random variables crating the pattern::
|
|
12
|
+
|
|
12
13
|
b -- d
|
|
13
14
|
/ | | \
|
|
14
15
|
a | | f
|
|
15
16
|
\ | | /
|
|
16
17
|
c -- e
|
|
18
|
+
|
|
17
19
|
If include_unaries then, also includes one unary factor per random variable.
|
|
18
20
|
"""
|
|
19
21
|
|
ck/example/truss.py
CHANGED
|
@@ -7,12 +7,14 @@ class Truss(PGM):
|
|
|
7
7
|
This PGM is the 'Truss' factor graph.
|
|
8
8
|
|
|
9
9
|
The Truss is a factor graph with five random variables (a, b, c, d, e).
|
|
10
|
-
Binary factors are between pairs of random variables creating the pattern
|
|
10
|
+
Binary factors are between pairs of random variables creating the pattern::
|
|
11
|
+
|
|
11
12
|
b ---- d
|
|
12
13
|
/ | / |
|
|
13
14
|
a | / |
|
|
14
15
|
\ | / |
|
|
15
16
|
c ---- e
|
|
17
|
+
|
|
16
18
|
If include_unaries then, also includes one unary factor per random variable.
|
|
17
19
|
"""
|
|
18
20
|
|
ck/in_out/parse_net.py
CHANGED
|
@@ -16,36 +16,37 @@ def read_network(input_stream, *, name: Optional[str] = None, network_builder: O
|
|
|
16
16
|
The input can be a string or a stream.
|
|
17
17
|
If the input is empty, then its is treated as an error.
|
|
18
18
|
|
|
19
|
-
This input is expected to conform to the following format
|
|
19
|
+
This input is expected to conform to the following format::
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
<network> ::= <net_block> <node_block>* <potential_block>*
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
<net_block> ::= 'net' <block>
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
<node_block> ::= 'node' <NAME> <block>
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
<potential_block> ::= 'potential' <link> <block>
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
<block> ::= '{' <sentence>* '}'
|
|
30
|
+
<sentence> ::= <NAME> '=' <value> ';'
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
<link> ::= '(' <NAME> ')'
|
|
33
|
+
| '(' <NAME> '|' <NAME>+ ')'
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
<value> ::= <STRING> | <NUMBER> | <list>
|
|
36
|
+
<list> ::='(' <value>* ')'
|
|
37
37
|
|
|
38
38
|
The sentences of a <net_block> are ignored.
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
In a <node_block>,
|
|
41
|
+
<name> of 'states' mandatory, with value that is a list of <STRING>
|
|
42
|
+
other sentences are ignored.
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
In a <potential_block>,
|
|
45
|
+
<name> of 'data' is mandatory, with value that is a list of (list of) <NUMBER> (shape matching the link)
|
|
46
|
+
other sentences are ignored.
|
|
47
|
+
|
|
48
|
+
Here is a simple example input::
|
|
47
49
|
|
|
48
|
-
Here is a simple example input:
|
|
49
50
|
net{}
|
|
50
51
|
node a
|
|
51
52
|
{
|
|
@@ -62,8 +63,9 @@ def read_network(input_stream, *, name: Optional[str] = None, network_builder: O
|
|
|
62
63
|
}
|
|
63
64
|
potential ( b | a )
|
|
64
65
|
{
|
|
65
|
-
data = ((0.4 0.4 0.2)(0.4 0.4 0.2))
|
|
66
|
+
data = ((0.4 0.4 0.2)(0.4 0.4 0.2));
|
|
66
67
|
}
|
|
68
|
+
|
|
67
69
|
"""
|
|
68
70
|
# Decorate the input stream
|
|
69
71
|
input_stream = ParserInput(input_stream)
|
ck/in_out/parser_utils.py
CHANGED
|
@@ -57,8 +57,10 @@ class ParserInput:
|
|
|
57
57
|
|
|
58
58
|
def readline(self) -> str:
|
|
59
59
|
"""
|
|
60
|
+
Read a line of input.
|
|
61
|
+
|
|
60
62
|
Returns:
|
|
61
|
-
the next line (including the trailing
|
|
63
|
+
the next line (including the trailing newline) or empty string if EOF.
|
|
62
64
|
"""
|
|
63
65
|
line = ''
|
|
64
66
|
while True:
|
|
@@ -69,9 +71,11 @@ class ParserInput:
|
|
|
69
71
|
|
|
70
72
|
def read_past_space(self, single_line: bool, comment_char=None) -> str:
|
|
71
73
|
"""
|
|
74
|
+
Read the input up to and including the first non-whitespace character.
|
|
75
|
+
|
|
72
76
|
Returns:
|
|
73
|
-
either empty string,
|
|
74
|
-
If single_line is True, then
|
|
77
|
+
either empty string, if end of input, otherwise a single character string that is not whitespace.
|
|
78
|
+
If single_line is True, then newline is treated as eof.
|
|
75
79
|
"""
|
|
76
80
|
c = self.read_one()
|
|
77
81
|
while True:
|
ck/pgm.py
CHANGED
|
@@ -15,33 +15,32 @@ from ck.utils.iter_extras import (
|
|
|
15
15
|
from ck.utils.np_extras import NDArrayFloat64, NDArrayUInt8
|
|
16
16
|
|
|
17
17
|
State: TypeAlias = Union[int, str, bool, float, None]
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"""
|
|
18
|
+
"""
|
|
19
|
+
The type for a possible state of a random variable.
|
|
20
|
+
"""
|
|
22
21
|
|
|
23
22
|
Instance: TypeAlias = Sequence[int]
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"""
|
|
23
|
+
"""
|
|
24
|
+
An instance (of a sequence of random variables) is a sequence of integers
|
|
25
|
+
that are state indexes, co-indexed with a known sequence of random variables.
|
|
26
|
+
"""
|
|
29
27
|
|
|
30
28
|
Key: TypeAlias = Union[Instance, int]
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"""
|
|
29
|
+
"""
|
|
30
|
+
A key identifies an instance, either as an instance itself or a
|
|
31
|
+
single integer, representing an instance with one dimension.
|
|
32
|
+
"""
|
|
36
33
|
|
|
37
34
|
Shape: TypeAlias = Sequence[int]
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"""
|
|
35
|
+
"""
|
|
36
|
+
The type for the "shape" of a sequence of random variables.
|
|
37
|
+
That is, the shape of (rv1, rv2, rv3) is (len(rv1), len(rv2), len(rv3)).
|
|
38
|
+
"""
|
|
43
39
|
|
|
44
|
-
DEFAULT_CPT_TOLERANCE: float = 0.000001
|
|
40
|
+
DEFAULT_CPT_TOLERANCE: float = 0.000001
|
|
41
|
+
"""
|
|
42
|
+
A tolerance when checking CPT distributions sum to one (or zero).
|
|
43
|
+
"""
|
|
45
44
|
|
|
46
45
|
|
|
47
46
|
class PGM:
|
|
@@ -214,14 +213,17 @@ class PGM:
|
|
|
214
213
|
The returned random variable will have an `idx` equal to the value of
|
|
215
214
|
`self.number_of_rvs` just prior to adding the new random variable.
|
|
216
215
|
|
|
216
|
+
The states of the random variable can be specified either as an integer
|
|
217
|
+
representing the number of states, or as a sequence of state values. If a
|
|
218
|
+
single integer, `n`, is provided then the states will be: 0, 1, ..., n-1.
|
|
219
|
+
If a sequence of states are provided then the states must be unique.
|
|
220
|
+
|
|
217
221
|
Assumes:
|
|
218
222
|
Provided states contain no duplicates.
|
|
219
223
|
|
|
220
224
|
Args:
|
|
221
225
|
name: a name for the random variable.
|
|
222
|
-
states: either
|
|
223
|
-
single integer, `n`, is provided then the states will be 0, 1, ..., n-1.
|
|
224
|
-
If a sequence of states are provided then the states must be unique.
|
|
226
|
+
states: either the number of states or a sequence of state values.
|
|
225
227
|
|
|
226
228
|
Returns:
|
|
227
229
|
a RandomVariable object belonging to this PGM.
|
|
@@ -241,10 +243,11 @@ class PGM:
|
|
|
241
243
|
|
|
242
244
|
Assumes:
|
|
243
245
|
The given random variables all belong to this PGM.
|
|
246
|
+
|
|
244
247
|
The random variables contain no duplicates.
|
|
245
248
|
|
|
246
249
|
Args:
|
|
247
|
-
|
|
250
|
+
rvs: the random variables.
|
|
248
251
|
|
|
249
252
|
Returns:
|
|
250
253
|
a Factor object belonging to this PGM.
|
|
@@ -336,17 +339,18 @@ class PGM:
|
|
|
336
339
|
*input_rvs: RandomVariable
|
|
337
340
|
) -> Factor:
|
|
338
341
|
"""
|
|
339
|
-
Add a sparse 0/1 factor to this PGM representing
|
|
340
|
-
|
|
341
|
-
|
|
342
|
+
Add a sparse 0/1 factor to this PGM representing `result_rv == function(*rvs)`.
|
|
343
|
+
That is::
|
|
344
|
+
|
|
342
345
|
factor[result_s, *input_s] = 1, if result_s == function(*input_s);
|
|
343
346
|
= 0, otherwise.
|
|
347
|
+
|
|
344
348
|
Args:
|
|
345
349
|
function: a function from state indexes of the input random variables to a state index
|
|
346
350
|
of the result random variable. The function should take the same number of arguments
|
|
347
351
|
as `input_rvs` and return a state index for `result_rv`.
|
|
348
352
|
result_rv: the random variable defining result values.
|
|
349
|
-
|
|
353
|
+
input_rvs: the random variables defining input values.
|
|
350
354
|
|
|
351
355
|
Returns:
|
|
352
356
|
a Factor object belonging to this PGM, with a configured sparse potential function.
|
|
@@ -378,16 +382,17 @@ class PGM:
|
|
|
378
382
|
"""
|
|
379
383
|
Render indicators as a string.
|
|
380
384
|
|
|
381
|
-
For example
|
|
385
|
+
For example::
|
|
382
386
|
pgm = PGM()
|
|
383
387
|
a = pgm.new_rv('A', ('x', 'y', 'z'))
|
|
384
388
|
b = pgm.new_rv('B', (3, 5))
|
|
385
389
|
print(pgm.indicator_str(a[0], b[1], a[2]))
|
|
386
|
-
|
|
390
|
+
|
|
391
|
+
will print::
|
|
387
392
|
A=x, B=5, A=z
|
|
388
393
|
|
|
389
394
|
Args:
|
|
390
|
-
|
|
395
|
+
indicators: the indicators to render.
|
|
391
396
|
sep: the separator to use between the random variable and its state.
|
|
392
397
|
delim: the delimiter to used when rendering multiple indicators.
|
|
393
398
|
|
|
@@ -406,16 +411,17 @@ class PGM:
|
|
|
406
411
|
"""
|
|
407
412
|
Render indicators as a string, grouping indicators by random variable.
|
|
408
413
|
|
|
409
|
-
For example
|
|
414
|
+
For example::
|
|
410
415
|
pgm = PGM()
|
|
411
416
|
a = pgm.new_rv('A', ('x', 'y', 'z'))
|
|
412
417
|
b = pgm.new_rv('B', (3, 5))
|
|
413
418
|
print(pgm.condition_str(a[0], b[1], a[2]))
|
|
414
|
-
|
|
419
|
+
|
|
420
|
+
will print::
|
|
415
421
|
A in {x, z}, B=5
|
|
416
422
|
|
|
417
423
|
Args:
|
|
418
|
-
|
|
424
|
+
indicators: the indicators to render.
|
|
419
425
|
Return:
|
|
420
426
|
a string representation of the given indicators, as a condition.
|
|
421
427
|
"""
|
|
@@ -930,9 +936,9 @@ class RandomVariable(Sequence[Indicator]):
|
|
|
930
936
|
in the random variable's PGM list of random variables.
|
|
931
937
|
|
|
932
938
|
A random variable behaves like a sequence of Indicators, where each indicator represents a random
|
|
933
|
-
variable being in a particular state. Specifically for a random variable rv, len(rv) is the
|
|
939
|
+
variable being in a particular state. Specifically for a random variable rv, `len(rv)` is the
|
|
934
940
|
number of states of the random variable and rv[i] is the Indicators representing that
|
|
935
|
-
rv is in the ith state. When sliced, the result is a tuple, i.e. rv[1:3] = (rv[1], rv[2])
|
|
941
|
+
rv is in the ith state. When sliced, the result is a tuple, i.e. `rv[1:3] = (rv[1], rv[2])`.
|
|
936
942
|
|
|
937
943
|
A RandomVariable has a name. This is for human convenience and has no functional purpose
|
|
938
944
|
within a PGM.
|
|
@@ -942,15 +948,18 @@ class RandomVariable(Sequence[Indicator]):
|
|
|
942
948
|
"""
|
|
943
949
|
Create a new random variable, in the given PGM.
|
|
944
950
|
|
|
951
|
+
The states of the random variable can be specified either as an integer
|
|
952
|
+
representing the number of states, or as a sequence of state values. If a
|
|
953
|
+
single integer, `n`, is provided then the states will be: 0, 1, ..., n-1.
|
|
954
|
+
If a sequence of states are provided then the states must be unique.
|
|
955
|
+
|
|
945
956
|
Assumes:
|
|
946
957
|
Provided states contain no duplicates.
|
|
947
958
|
|
|
948
959
|
Args:
|
|
949
960
|
pgm: the PGM that the random variable will belong to.
|
|
950
961
|
name: a name for the random variable.
|
|
951
|
-
states: either
|
|
952
|
-
single integer, `n`, is provided then the states will be 0, 1, ..., n-1.
|
|
953
|
-
If a sequence of states are provided then the states must be unique.
|
|
962
|
+
states: either the number of states or a sequence of state values.
|
|
954
963
|
"""
|
|
955
964
|
self._pgm: PGM = pgm
|
|
956
965
|
self._name: str = name
|
|
@@ -1212,15 +1221,14 @@ class RVMap(Sequence[RandomVariable]):
|
|
|
1212
1221
|
In addition to accessing a random variable by its index, an RVMap enables
|
|
1213
1222
|
access to the PGM random variable via the name of each random variable.
|
|
1214
1223
|
|
|
1215
|
-
For example, if `pgm.rvs[1]` is a random variable named `xray`, then
|
|
1216
|
-
|
|
1217
|
-
|
|
1224
|
+
For example, if `pgm.rvs[1]` is a random variable named `xray`, then::
|
|
1225
|
+
|
|
1226
|
+
rvs = RVMap(pgm)
|
|
1218
1227
|
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
```
|
|
1228
|
+
# These all retrieve the same random variable object.
|
|
1229
|
+
xray = rvs[1]
|
|
1230
|
+
xray = rvs('xray')
|
|
1231
|
+
xray = rvs.xray
|
|
1224
1232
|
|
|
1225
1233
|
To use an RVMap on a PGM, the random variable names must be unique across the PGM.
|
|
1226
1234
|
"""
|
|
@@ -1527,7 +1535,7 @@ class Factor:
|
|
|
1527
1535
|
Set to the potential function to a new `ClausePotentialFunction` object.
|
|
1528
1536
|
|
|
1529
1537
|
Args:
|
|
1530
|
-
|
|
1538
|
+
key: defines the random variable states of the clause. The key is a sequence of
|
|
1531
1539
|
random variable state indexes, co-indexed with `Factor.rvs`.
|
|
1532
1540
|
|
|
1533
1541
|
Returns:
|
|
@@ -1556,7 +1564,7 @@ class Factor:
|
|
|
1556
1564
|
return self._potential_function
|
|
1557
1565
|
|
|
1558
1566
|
|
|
1559
|
-
@dataclass(frozen=True, eq=True)
|
|
1567
|
+
@dataclass(frozen=True, eq=True, slots=True)
|
|
1560
1568
|
class ParamId:
|
|
1561
1569
|
"""
|
|
1562
1570
|
A ParamId identifies a parameter of a potential function.
|
|
@@ -2164,7 +2172,7 @@ class DensePotentialFunction(PotentialFunction):
|
|
|
2164
2172
|
"""
|
|
2165
2173
|
Set the values of the potential function using the given iterator.
|
|
2166
2174
|
|
|
2167
|
-
Mapping instances to
|
|
2175
|
+
Mapping instances to values is as follows:
|
|
2168
2176
|
Given Factor(rv1, rv2) where rv1 has 2 states, and rv2 has 3 states:
|
|
2169
2177
|
values[0] represents instance (0,0)
|
|
2170
2178
|
values[1] represents instance (0,1)
|
|
@@ -2209,7 +2217,7 @@ class DensePotentialFunction(PotentialFunction):
|
|
|
2209
2217
|
The order of values is the same as set_iter.
|
|
2210
2218
|
|
|
2211
2219
|
Args:
|
|
2212
|
-
|
|
2220
|
+
value: the values to use.
|
|
2213
2221
|
|
|
2214
2222
|
Returns:
|
|
2215
2223
|
self
|
|
@@ -2414,7 +2422,7 @@ class SparsePotentialFunction(PotentialFunction):
|
|
|
2414
2422
|
"""
|
|
2415
2423
|
Set the values of the potential function using the given iterator.
|
|
2416
2424
|
|
|
2417
|
-
Mapping instances to
|
|
2425
|
+
Mapping instances to values is as follows:
|
|
2418
2426
|
Given Factor(rv1, rv2) where rv1 has 2 states, and rv2 has 3 states:
|
|
2419
2427
|
values[0] represents instance (0,0)
|
|
2420
2428
|
values[1] represents instance (0,1)
|
|
@@ -2636,7 +2644,7 @@ class CompactPotentialFunction(PotentialFunction):
|
|
|
2636
2644
|
"""
|
|
2637
2645
|
Set the values of the potential function using the given iterator.
|
|
2638
2646
|
|
|
2639
|
-
Mapping instances to
|
|
2647
|
+
Mapping instances to `values` is as follows:
|
|
2640
2648
|
Given Factor(rv1, rv2) where rv1 has 2 states, and rv2 has 3 states:
|
|
2641
2649
|
values[0] represents instance (0,0)
|
|
2642
2650
|
values[1] represents instance (0,1)
|
|
@@ -2679,7 +2687,7 @@ class CompactPotentialFunction(PotentialFunction):
|
|
|
2679
2687
|
The order of values is the same as set_iter.
|
|
2680
2688
|
|
|
2681
2689
|
Args:
|
|
2682
|
-
|
|
2690
|
+
value: the values to use.
|
|
2683
2691
|
|
|
2684
2692
|
Returns:
|
|
2685
2693
|
self
|
|
@@ -3071,7 +3079,8 @@ class CPTPotentialFunction(PotentialFunction):
|
|
|
3071
3079
|
Calls self.set_cpd(parent_states, cpd) for each row (parent_states, cpd)
|
|
3072
3080
|
in rows. Any unmentioned parent states will have zero probabilities.
|
|
3073
3081
|
|
|
3074
|
-
Example usage, assuming three Boolean random variables
|
|
3082
|
+
Example usage, assuming three Boolean random variables::
|
|
3083
|
+
|
|
3075
3084
|
pgm.Factor(x, y, z).set_cpt().set(
|
|
3076
3085
|
# y z x[0] x[1]
|
|
3077
3086
|
((0, 0), (0.1, 0.9)),
|
|
@@ -3079,9 +3088,9 @@ class CPTPotentialFunction(PotentialFunction):
|
|
|
3079
3088
|
((1, 0), (0.1, 0.9)),
|
|
3080
3089
|
((1, 1), (0.1, 0.9))
|
|
3081
3090
|
)
|
|
3082
|
-
|
|
3091
|
+
|
|
3083
3092
|
Args:
|
|
3084
|
-
|
|
3093
|
+
rows: are tuples (key, cpd) used to set the potential function values.
|
|
3085
3094
|
|
|
3086
3095
|
Raises:
|
|
3087
3096
|
ValueError: if a CPD is not valid.
|
|
@@ -3105,7 +3114,7 @@ class CPTPotentialFunction(PotentialFunction):
|
|
|
3105
3114
|
Any list entry may be None, indicating 'guaranteed zero' for the associated parent states.
|
|
3106
3115
|
|
|
3107
3116
|
Args:
|
|
3108
|
-
|
|
3117
|
+
cpds: are the CPDs used to set the potential function values.
|
|
3109
3118
|
|
|
3110
3119
|
Raises:
|
|
3111
3120
|
ValueError: if a CPD is not valid.
|
ck/pgm_circuit/mpe_program.py
CHANGED
|
@@ -228,10 +228,9 @@ class MPEProgram(ProgramWithSlotmap):
|
|
|
228
228
|
class MPEResult:
|
|
229
229
|
"""
|
|
230
230
|
An MPE result is the result of MPE inference.
|
|
231
|
-
|
|
232
|
-
Fields:
|
|
233
|
-
wmc: the weighted model count value of the MPE solution.
|
|
234
|
-
mpe: The MPE solution instance. If there are ties then this will just be once instance.
|
|
235
231
|
"""
|
|
236
232
|
wmc: float
|
|
233
|
+
"""the weighted model count value of the MPE solution."""
|
|
234
|
+
|
|
237
235
|
mpe: Instance
|
|
236
|
+
"""the MPE solution instance. If there are ties then this will just be once instance."""
|
ck/pgm_circuit/pgm_circuit.py
CHANGED
|
@@ -16,33 +16,42 @@ class PGMCircuit:
|
|
|
16
16
|
holds the values of the parameters. Specifically, given parameter id `param_id`, then
|
|
17
17
|
`parameter_values[slot_map[param_id] - number_of_indicators]` is the value of the
|
|
18
18
|
identified parameter as it was in the PGM.
|
|
19
|
-
|
|
20
|
-
Fields:
|
|
21
|
-
rvs: holds the random variables from the PGM as it was compiled, in order.
|
|
22
|
-
|
|
23
|
-
conditions: any conditions on `rvs` that were compiled into the circuit.
|
|
24
|
-
|
|
25
|
-
number_of_indicators: is the number of indicators in `rvs` which is
|
|
26
|
-
`sum(len(rv) for rv in rvs`. Specifically, `circuit.vars[i]` is the circuit variable
|
|
27
|
-
corresponding to the ith indicator, where `circuit` is `circuit_top.circuit` and
|
|
28
|
-
indicators are ordered as per `rvs`.
|
|
29
|
-
|
|
30
|
-
number_of_parameters: is the number of parameters from the PGM that are
|
|
31
|
-
represented as circuit variables. This may be zero if parameters from the PGM
|
|
32
|
-
were compiled as constants.
|
|
33
|
-
|
|
34
|
-
slot_map[x]: gives the index of the circuit variable corresponding to x,
|
|
35
|
-
where x is either a random variable indicator (Indicator) or a parameter id (ParamId).
|
|
36
|
-
|
|
37
19
|
"""
|
|
38
20
|
|
|
39
21
|
rvs: Sequence[RandomVariable]
|
|
22
|
+
"""holds the random variables from the PGM as it was compiled, in order."""
|
|
23
|
+
|
|
40
24
|
conditions: Sequence[Indicator]
|
|
25
|
+
"""any conditions on `rvs` that were compiled into the circuit."""
|
|
26
|
+
|
|
41
27
|
circuit_top: CircuitNode
|
|
28
|
+
"""the top circuit node defining the network function."""
|
|
29
|
+
|
|
42
30
|
number_of_indicators: int
|
|
31
|
+
"""
|
|
32
|
+
the number of indicators in `rvs` which is
|
|
33
|
+
`sum(len(rv) for rv in rvs`. Specifically, `circuit.vars[i]` is the circuit variable
|
|
34
|
+
corresponding to the ith indicator, where `circuit` is `circuit_top.circuit` and
|
|
35
|
+
indicators are ordered as per `rvs`.
|
|
36
|
+
"""
|
|
37
|
+
|
|
43
38
|
number_of_parameters: int
|
|
39
|
+
"""
|
|
40
|
+
the number of parameters from the PGM that are
|
|
41
|
+
represented as circuit variables. This may be zero if parameters from the PGM
|
|
42
|
+
were compiled as constants.
|
|
43
|
+
"""
|
|
44
|
+
|
|
44
45
|
slot_map: SlotMap
|
|
46
|
+
"""
|
|
47
|
+
gives the index of the circuit variable corresponding to x,
|
|
48
|
+
where x is either a random variable indicator (Indicator) or a parameter id (ParamId).
|
|
49
|
+
"""
|
|
50
|
+
|
|
45
51
|
parameter_values: NDArray
|
|
52
|
+
"""
|
|
53
|
+
parameter values, co-indexed with the circuit variables, counting beyond `number_of_indicators`.
|
|
54
|
+
"""
|
|
46
55
|
|
|
47
56
|
def dump(self, *, prefix: str = '', indent: str = ' ') -> None:
|
|
48
57
|
"""
|
|
@@ -114,7 +114,10 @@ class ProgramWithSlotmap:
|
|
|
114
114
|
|
|
115
115
|
def compute_conditioned(self, *condition: Condition) -> NDArrayNumeric:
|
|
116
116
|
"""
|
|
117
|
-
|
|
117
|
+
Compute the program value, after setting the given condition.
|
|
118
|
+
|
|
119
|
+
Equivalent to::
|
|
120
|
+
|
|
118
121
|
self.set_condition(*condition)
|
|
119
122
|
return self.compute()
|
|
120
123
|
"""
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"/O2"
|
|
14
14
|
],
|
|
15
15
|
"include_dirs": [
|
|
16
|
-
"C:\\Users\\runneradmin\\AppData\\Local\\Temp\\build-env-
|
|
16
|
+
"C:\\Users\\runneradmin\\AppData\\Local\\Temp\\build-env-8cwjzb8_\\Lib\\site-packages\\numpy\\_core\\include"
|
|
17
17
|
],
|
|
18
18
|
"name": "ck.pgm_compiler.support.circuit_table._circuit_table_cy",
|
|
19
19
|
"sources": [
|
|
Binary file
|
|
@@ -11,17 +11,16 @@ from ck.utils.map_set import MapSet
|
|
|
11
11
|
from ck.utils.np_extras import dtype_for_number_of_states, NDArrayFloat64, DTypeStates, NDArrayNumeric
|
|
12
12
|
|
|
13
13
|
Condition: TypeAlias = None | Indicator | Iterable[Indicator]
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"""
|
|
14
|
+
"""
|
|
15
|
+
Type defining a condition. A condition is logically a set of
|
|
16
|
+
indicators, each indicator representing a random variable being in some state.
|
|
17
|
+
|
|
18
|
+
If multiple indicators of the same random variable appear in
|
|
19
|
+
a condition, then they are interpreted as
|
|
20
|
+
a disjunction, otherwise indicators are interpreted as
|
|
21
|
+
a conjunction. E.g., the condition (X=0, Y=1, Y=3) means
|
|
22
|
+
X=0 and (Y=1 or Y=3).
|
|
23
|
+
"""
|
|
25
24
|
|
|
26
25
|
_NAN: float = np.nan # Not-a-number (i.e., the result of an invalid calculation).
|
|
27
26
|
|