forked from jataware/NeticaPy3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNeticaPy.pyx
3128 lines (2341 loc) · 112 KB
/
NeticaPy.pyx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from libc.stdlib cimport malloc, # free
import types
from cpython.object cimport PyObject
import cython
cdef extern from "Python.h":
char* PyUnicode_AsUTF8(PyObject *unicode)
cdef char ** to_cstring_array(list_str):
cdef char **ret = <char **>malloc(len(list_str) * sizeof(char *))
for i in xrange(len(list_str)):
ret[i] = PyUnicode_AsUTF8(<PyObject*>list_str[i])
return ret
cdef extern from "Netica.h":
cdef enum:
EVERY_STATE =-5,
IMPOSS_STATE,
UNDEF_STATE
ctypedef struct environ_ns:
pass
ctypedef struct report_ns:
pass
ctypedef struct stream_ns:
pass
ctypedef struct randgen_ns:
pass
ctypedef struct scripter_ns:
pass
ctypedef struct net_bn:
pass
ctypedef struct node_bn:
pass
ctypedef struct nodelist_bn:
pass
ctypedef struct caseset_cs:
pass
ctypedef struct learner_bn:
pass
ctypedef struct tester_bn:
pass
ctypedef struct sensv_bn:
pass
ctypedef struct setting_bn:
pass
ctypedef struct dbmgr_cs:
pass
ctypedef enum errseverity_ns:
NOTHING_ERR=1,
REPORT_ERR,
NOTICE_ERR,
WARNING_ERR,
ERROR_ERR,
XXX_ERR
ctypedef int state_bn
ctypedef float prob_bn
ctypedef float util_bn
ctypedef double level_bn
ctypedef int color_ns
ctypedef long caseposn_bn
ctypedef unsigned char bool_ns
ctypedef enum sampling_bn:
DEFAULT_SAMPLING,
JOIN_TREE_SAMPLING,
FORWARD_SAMPLING
ctypedef enum checking_ns:
NO_CHECK=1,
QUICK_CHECK,
REGULAR_CHECK,
COMPLETE_CHECK,
QUERY_CHECK=-1
ctypedef enum errseverity_ns:
NOTHING_ERR=1,
REPORT_ERR,
NOTICE_ERR,
WARNING_ERR,
ERROR_ERR,
XXX_ERR
ctypedef enum errcond_ns:
OUT_OF_MEMORY_CND=0x08,
USER_ABORTED_CND=0x20,
FROM_WRAPPER_CND=0x40,
FROM_DEVELOPER_CND=0x80,
INCONS_FINDING_CND=0x200
ctypedef enum eventtype_ns:
CREATE_EVENT=0x01,
DUPLICATE_EVENT=0x02,
REMOVE_EVENT=0x04
ctypedef enum nodetype_bn:
CONTINUOUS_TYPE=1,
DISCRETE_TYPE,
TEXT_TYPE
ctypedef enum nodekind_bn:
NATURE_NODE=1,
CONSTANT_NODE,
DECISION_NODE,
UTILITY_NODE,
DISCONNECTED_NODE,
ADVERSARY_NODE
cdef enum:
REAL_VALUE = -25,
STATE_VALUE = -20,
GAUSSIAN_VALUE = -15,
INTERVAL_VALUE = -10,
STATE_NOT_VALUE = -7,
LIKELIHOOD_VALUE,
NO_VALUE = -3
cdef enum:
EVERY_STATE = -5,
IMPOSS_STATE,
UNDEF_STATE
cdef enum:
FIRST_CASE = -15,
NEXT_CASE,
NO_MORE_CASES
cdef enum:
ENTROPY_SENSV = 0x02,
REAL_SENSV = 0x04,
VARIANCE_SENSV = 0x100,
VARIANCE_OF_REAL_SENSV = 0x104
ctypedef enum learn_method_bn:
COUNTING_LEARNING=1,
EM_LEARNING=3,
GRADIENT_DESCENT_LEARNING
cdef enum:
NEGATIVE_FINDING = -7,
LIKELIHOOD_FINDING,
NO_FINDING = -3
cdef enum:
NO_VISUAL_INFO=0,
NO_WINDOW=0x10,
MINIMIZED_WINDOW=0x30,
REGULAR_WINDOW=0x70
cdef enum:
BELIEF_UPDATE = 0x100
cdef enum:
HALT_CALLBACK_RESULT = -1003
cdef enum:
ALL_THREADS = 0x20
cdef enum:
LAST_ENTRY = -10
cdef enum:
QUERY_ns = -1
environ_ns* NewNeticaEnviron_ns (const char* license, environ_ns* env, const char* locn)
int InitNetica2_bn (environ_ns* env, char* mesg)
int CloseNetica_bn (environ_ns* env, char* mesg)
int GetNeticaVersion_bn (const environ_ns* env, const char** version)
checking_ns ArgumentChecking_ns (checking_ns setting, environ_ns* env)
void SetPassword_ns (environ_ns* env, const char* password, const char* options)
const char* SetLanguage_ns (environ_ns* env, const char* language)
double LimitMemoryUsage_ns (double max_mem, environ_ns* env)
void SetEnvironUserData_ns (environ_ns* env, int kind, void* data)
void* GetEnvironUserData_ns (environ_ns* env, int kind)
report_ns* GetError_ns (environ_ns* env, errseverity_ns severity, const report_ns* after)
int ErrorNumber_ns (const report_ns* error)
const char* ErrorMessage_ns (const report_ns* error)
errseverity_ns ErrorSeverity_ns (const report_ns* error)
bool_ns ErrorCategory_ns (errcond_ns cond, const report_ns* error)
void ClearError_ns (report_ns* error)
void ClearErrors_ns (environ_ns* env, errseverity_ns severity)
report_ns* NewError_ns (environ_ns* env, int number, errseverity_ns severity, const char* mesg)
int TestFaultRecovery_ns (environ_ns* env, int test_num)
int UserAllowed_ns (environ_ns* env, int setting)
void GetAppWindowPosition_ns (environ_ns* env, int* left, int* top, int* width, int* height, int* status)
void SetAppWindowPosition_ns (environ_ns* env, int left, int top, int width, int height, int status)
void PrintToMessagesWindow_ns (environ_ns* env, char* mesg)
stream_ns* NewFileStream_ns (const char* filename, environ_ns* env, const char* access)
stream_ns* NewMemoryStream_ns (const char* name, environ_ns* env, const char* access)
void DeleteStream_ns (stream_ns* file)
void SetStreamPassword_ns (stream_ns* stream, const char* password)
void SetStreamContents_ns (stream_ns* stream, const char* buffer, long length, bool_ns copy)
const char* GetStreamContents_ns (stream_ns* stream, long* length)
void WriteNet_bn (const net_bn* net, stream_ns* file)
net_bn* ReadNet_bn (stream_ns* file, int options)
caseposn_bn WriteNetFindings_bn (const nodelist_bn* nodes, stream_ns* file, long ID_num, double freq)
void ReadNetFindings2_bn (caseposn_bn* case_posn, stream_ns* file, bool_ns add, const nodelist_bn* nodes, long* ID_num, double* freq)
int SetCaseFileDelimChar_ns (int newchar, environ_ns* env)
int SetMissingDataChar_ns (int newchar, environ_ns* env)
net_bn* NewNet_bn (const char* name, environ_ns* env)
net_bn* CopyNet_bn (const net_bn* net, const char* new_name, environ_ns* new_env, const char* options)
void DeleteNet_bn (net_bn* net)
net_bn* GetNthNet_bn (int nth, environ_ns* env)
node_bn* NewNode_bn (const char* name, int num_states, net_bn* net)
nodelist_bn* CopyNodes_bn (const nodelist_bn* nodes, net_bn* new_net, const char* options)
void DeleteNode_bn (node_bn* node)
void SetNetName_bn (net_bn* net, const char* name)
void SetNetTitle_bn (net_bn* net, const char* title)
void SetNetComment_bn (net_bn* net, const char* comment)
void SetNetElimOrder_bn (net_bn* net, const nodelist_bn* elim_order)
int SetNetAutoUpdate_bn (net_bn* net, int auto_update)
void SetNetUserField_bn (net_bn* net, const char* name, const void* data, int length, int kind)
void SetNetUserData_bn (net_bn* net, int kind, void* data)
void AddNetListener_bn (net_bn* net, int callback (const net_bn* net, eventtype_ns what, void* object, void* info), void* object, int filter)
void SetNodeName_bn (node_bn* node, const char* name)
void SetNodeTitle_bn (node_bn* node, const char* title)
void SetNodeComment_bn (node_bn* node, const char* comment)
void SetNodeLevels_bn (node_bn* node, int num_states, const level_bn* levels)
void SetNodeKind_bn (node_bn* node, nodekind_bn kind)
void SetNodeStateName_bn (node_bn* node, state_bn state, const char* state_name)
void SetNodeStateNames_bn (node_bn* node, const char* state_names)
void SetNodeStateTitle_bn (node_bn* node, state_bn state, const char* state_title)
void SetNodeStateComment_bn (node_bn* node, state_bn state, const char* state_comment)
void SetNodeInputName_bn (node_bn* node, int link_index, const char* link_name)
void SetNodeEquation_bn (node_bn* node, const char* eqn)
void SetNodeFuncState_bn (node_bn* node, const state_bn* parent_states, state_bn st)
void SetNodeFuncReal_bn (node_bn* node, const state_bn* parent_states, double val)
void SetNodeProbs_bn (node_bn* node, const state_bn* parent_states, const prob_bn* probs)
void SetNodeExperience_bn (node_bn* node, const state_bn* parent_states, double experience)
void DeleteNodeTables_bn (node_bn* node)
void SetNodeUserField_bn (node_bn* node, const char* name, const void* data, int length, int kind)
void SetNodeUserData_bn (node_bn* node, int kind, void* data)
void AddNodeListener_bn (node_bn* node, int callback (const node_bn* node, eventtype_ns what, void* object, void* info), void* object, int filter)
void SetNodeVisPosition_bn (node_bn* node, void* vis, double x, double y)
void SetNodeVisStyle_bn (node_bn* node, void* vis, const char* style)
const char* GetNetName_bn (const net_bn* net)
const char* GetNetTitle_bn (const net_bn* net)
const char* GetNetComment_bn (const net_bn* net)
const nodelist_bn* GetNetNodes2_bn (const net_bn* net, const char options[])
node_bn* GetNodeNamed_bn (const char* name, const net_bn* net)
const char* GetNetFileName_bn (const net_bn* net)
int GetNetAutoUpdate_bn (const net_bn* net)
const nodelist_bn* GetNetElimOrder_bn (const net_bn* net)
const char* GetNetUserField_bn (const net_bn* net, const char* name, int* length, int kind)
void GetNetNthUserField_bn (const net_bn* net, int index, const char** name, const char** value, int* length, int kind)
void* GetNetUserData_bn (const net_bn* net, int kind)
net_bn* GetNodeNet_bn (const node_bn* node)
const char* GetNodeName_bn (const node_bn* node)
const char* GetNodeTitle_bn (const node_bn* node)
const char* GetNodeComment_bn (const node_bn* node)
nodetype_bn GetNodeType_bn (const node_bn* node)
nodekind_bn GetNodeKind_bn (const node_bn* node)
int GetNodeNumberStates_bn (const node_bn* node)
const level_bn* GetNodeLevels_bn (const node_bn* node)
const char* GetNodeStateName_bn (const node_bn* node, state_bn state)
const char* GetNodeStateTitle_bn (const node_bn* node, state_bn state)
const char* GetNodeStateComment_bn (const node_bn* node, state_bn state)
state_bn GetStateNamed_bn (const char* name, const node_bn* node)
const nodelist_bn* GetNodeParents_bn (const node_bn* node)
const nodelist_bn* GetNodeChildren_bn (const node_bn* node)
const char* GetNodeInputName_bn (const node_bn* node, int link_index)
int GetInputNamed_bn (const char* name, const node_bn* node)
const char* GetNodeEquation_bn (const node_bn* node)
state_bn GetNodeFuncState_bn (const node_bn* node, const state_bn* parent_states)
double GetNodeFuncReal_bn (const node_bn* node, const state_bn* parent_states)
const prob_bn* GetNodeProbs_bn (const node_bn* node, const state_bn* parent_states)
double GetNodeExperience_bn (const node_bn* node, const state_bn* parent_states)
bool_ns HasNodeTable_bn (const node_bn* node, bool_ns* complete)
bool_ns IsNodeDeterministic_bn (const node_bn* node)
const char* GetNodeUserField_bn (const node_bn* node, const char* name, int* length, int kind)
void GetNodeNthUserField_bn (const node_bn* node, int index, const char** name, const char** value, int* length, int kind)
void* GetNodeUserData_bn (const node_bn* node, int kind)
void GetNodeVisPosition_bn (const node_bn* node, void* vis, double* x, double* y)
const char* GetNodeVisStyle_bn (const node_bn* node, void* vis)
int AddLink_bn (node_bn* parent, node_bn* child)
void DeleteLink_bn (int link_index, node_bn* child)
void SwitchNodeParent_bn (int link_index, node_bn* node, node_bn* new_parent)
bool_ns IsNodeRelated_bn (const node_bn* related_node, const char* relation, const node_bn* node)
void GetRelatedNodes_bn (nodelist_bn* related_nodes, const char* relation, const node_bn* node)
void GetRelatedNodesMult_bn (nodelist_bn* related_nodes, const char* relation, const nodelist_bn* nodes)
nodelist_bn* NewNodeList2_bn (int length, const net_bn* net)
void DeleteNodeList_bn (nodelist_bn* nodes)
void ClearNodeList_bn (nodelist_bn* nodes)
int LengthNodeList_bn (const nodelist_bn* nodes)
void AddNodeToList_bn (node_bn* node, nodelist_bn* nodes, int index)
node_bn* RemoveNthNode_bn (nodelist_bn* nodes, int index)
node_bn* NthNode_bn (const nodelist_bn* nodes, int index)
void SetNthNode_bn (nodelist_bn* nodes, int index, node_bn* node)
int IndexOfNodeInList_bn (const node_bn* node, const nodelist_bn* nodes, int start_index)
nodelist_bn* DupNodeList_bn (const nodelist_bn* nodes)
void MapStateList_bn (const state_bn* src_states, const nodelist_bn* src_nodes, state_bn* dest_states, const nodelist_bn* dest_nodes)
void ReviseCPTsByFindings_bn (const nodelist_bn* nodes, int updating, double degree)
void ReviseCPTsByCaseFile_bn (stream_ns* file, const nodelist_bn* nodes, int updating, double degree)
void FadeCPTable_bn (node_bn* node, double degree)
void AddNodeStates_bn (node_bn* node, state_bn first_state, const char* state_names, int num_states, double cpt_fill)
void RemoveNodeState_bn (node_bn* node, state_bn state)
void ReorderNodeStates_bn (node_bn* node, const state_bn* new_order)
void EquationToTable_bn (node_bn* node, int num_samples, bool_ns samp_unc, bool_ns add_exist)
void ReverseLink_bn (node_bn* parent, node_bn* child)
void AbsorbNodes_bn (nodelist_bn* nodes)
void EnterFinding_bn (node_bn* node, state_bn state)
void EnterFindingNot_bn (node_bn* node, state_bn state)
void EnterNodeValue_bn (node_bn* node, double value)
void EnterNodeLikelihood_bn (node_bn* node, const prob_bn* likelihood)
void EnterNodeCalibration_bn (node_bn* node, const prob_bn* calibration)
void EnterIntervalFinding_bn (node_bn* node, double low, double high)
void EnterGaussianFinding_bn (node_bn* node, double mean, double std_dev)
state_bn GetNodeFinding_bn (const node_bn* node)
double GetNodeValueEntered_bn (const node_bn* node)
const prob_bn* GetNodeLikelihood_bn (const node_bn* node)
void RetractNodeFindings_bn (node_bn* node)
void RetractNetFindings_bn (net_bn* net)
state_bn CalcNodeState_bn (node_bn* node)
double CalcNodeValue_bn (node_bn* node)
void CompileNet_bn (net_bn* net)
void UncompileNet_bn (net_bn* net)
double SizeCompiledNet_bn (net_bn* net, int method)
bool_ns IsBeliefUpdated_bn (const node_bn* node)
const prob_bn* GetNodeBeliefs_bn (node_bn* node)
double GetNodeExpectedValue_bn (node_bn* node, double* std_dev, double* x3, double* x4)
const util_bn* GetNodeExpectedUtils_bn (node_bn* node)
double FindingsProbability_bn (net_bn* net)
util_bn GetNetExpectedUtility_bn (net_bn* net)
double JointProbability_bn (const nodelist_bn* nodes, const state_bn* states)
void MostProbableConfig_bn (const nodelist_bn* nodes, state_bn* config, int nth)
sensv_bn* NewSensvToFinding_bn (const node_bn* t_node, const nodelist_bn* v_nodes, int what_calc)
void DeleteSensvToFinding_bn (sensv_bn* s)
double GetMutualInfo_bn (sensv_bn* s, const node_bn* v_node)
double GetVarianceOfReal_bn (sensv_bn* s, const node_bn* v_node)
int GenerateRandomCase_bn (const nodelist_bn* nodes, sampling_bn method, double num, randgen_ns* rand)
void AddNodeToNodeset_bn (node_bn* node, const char* nodeset)
void RemoveNodeFromNodeset_bn (node_bn* node, const char* nodeset)
bool_ns IsNodeInNodeset_bn (const node_bn* node, const char* nodeset)
const char* GetAllNodesets_bn (const net_bn* net, bool_ns include_system, void* vis)
color_ns SetNodesetColor_bn (const char* nodeset, color_ns color, net_bn* net, void* vis)
void ReorderNodesets_bn (net_bn* net, const char* nodeset_order, void* vis)
caseset_cs* NewCaseset_cs (const char* name, environ_ns* env)
void DeleteCaseset_cs (caseset_cs* cases)
void AddFileToCaseset_cs (caseset_cs* cases, const stream_ns* file, double degree, const char* options)
void WriteCaseset_cs (const caseset_cs* cases, stream_ns* file, const char* options)
dbmgr_cs* NewDBManager_cs (const char* connect_str, const char* options, environ_ns* env)
void DeleteDBManager_cs (dbmgr_cs* dbmgr)
void ExecuteDBSql_cs (dbmgr_cs* dbmgr, const char* sql_cmnd, const char* options)
void InsertFindingsIntoDB_bn (dbmgr_cs* dbmgr, const nodelist_bn* nodes, const char* column_names, const char* tables, const char* options)
void AddDBCasesToCaseset_cs (caseset_cs* cases, dbmgr_cs* dbmgr, double degree, const nodelist_bn* nodes, const char* column_names, const char* tables, const char* condition, const char* options)
void AddNodesFromDB_bn (dbmgr_cs* dbmgr, net_bn* net, const char* column_names, const char* tables, const char* condition, const char* options)
learner_bn* NewLearner_bn (learn_method_bn method, const char* options, environ_ns* env)
void DeleteLearner_bn (learner_bn* algo)
int SetLearnerMaxIters_bn (learner_bn* algo, int max_iters)
double SetLearnerMaxTol_bn (learner_bn* algo, double log_likeli_tol)
void LearnCPTs_bn (learner_bn* algo, const nodelist_bn* nodes, const caseset_cs* cases, double degree)
tester_bn* NewNetTester_bn (const nodelist_bn* test_nodes, const nodelist_bn* unobsv_nodes, int tests)
void DeleteNetTester_bn (tester_bn* test)
void TestWithCaseset_bn (tester_bn* test, const caseset_cs* cases)
double GetTestErrorRate_bn (const tester_bn* test, const node_bn* node)
double GetTestLogLoss_bn (const tester_bn* test, const node_bn* node)
double GetTestQuadraticLoss_bn (const tester_bn* test, const node_bn* node)
double GetTestConfusion_bn (const tester_bn* test, const node_bn* node, state_bn predicted, state_bn actual)
void SetNetNumUndos_bn (net_bn* net, int count_limit, double memory_limit, const char* options)
int UndoNetLastOper_bn (net_bn* net, double to_when)
int RedoNetOper_bn (net_bn* net, double to_when)
int GetNodeLabel_bn (const node_bn* node, unsigned short* label, int max_chars, const char* options)
int GetNodeStateLabel_bn (const node_bn* node, state_bn state, unsigned short* label, int max_chars, const char* options)
const char* CreateCustomReport_bn (net_bn* net, const nodelist_bn* sel_nodes, const char* templat, const char* options)
const char* ControlConcurrency_ns (environ_ns* env, const char* command, const char* value)
const char* ControlNetCaching_bn (net_bn* net, const char* command, const char* value, const nodelist_bn* nodes)
net_bn* ExpandNet_bn (net_bn* net, int dimn, double result_time, double burn_time, const char* options)
void SetNodeInputDelay_bn (node_bn* node, int link_index, int dimension, const char* delay)
void SetNodePersistance_bn (node_bn* node, int dimension, const char* persistance)
node_bn* GetNodeAtTime_bn (net_bn* net, const char* name, double* time)
randgen_ns* NewRandomGenerator_ns (const char* seed, environ_ns* env, const char* options)
void DeleteRandomGen_ns (randgen_ns* rand)
const char* GetRandomGenState_ns (randgen_ns* rand, const char* options)
double GenerateRandomNumbers_ns (randgen_ns* rand, double* results, int num, const char* options)
void SetNetRandomGen_bn (net_bn* net, randgen_ns* rand, bool_ns is_private)
void EnterAction_bn (node_bn* node, state_bn state)
void EnterActionValue_bn (node_bn* node, double value)
void EnterActionRandomized_bn (node_bn* node, const prob_bn* probs)
void CleanupThreadEnding_ns (environ_ns* env)
scripter_ns* NewScripter_ns (environ_ns* env, const char* file_name, const char* language, const char* options, const char* script)
void DeleteScripter_ns (scripter_ns* scr)
const char* ExecuteScript_ns (scripter_ns* scr, const char* options)
void StartScriptRecorder_ns (scripter_ns* scr, const char* file_name, const char* language, const char* options)
const char* StopScriptRecorder_ns (scripter_ns* scr, const char* file_name, const char* options)
const char* GetScriptVar_ns (scripter_ns* scr, const char* name, const char* type)
void ClearScriptVars_ns (scripter_ns* scr, const char* options)
setting_bn* NewSetting_bn (const nodelist_bn* nodes, bool_ns load)
void DeleteSetting_bn (setting_bn* cas)
void SetSettingState_bn (setting_bn* cas, const node_bn* node, state_bn state)
state_bn GetSettingState_bn (const setting_bn* cas, const node_bn* node)
void ZeroSetting_bn (setting_bn* cas)
bool_ns NextSetting_bn (setting_bn* cas)
void MostProbableSetting_bn (net_bn* net, setting_bn* cas, int nth)
double NthProb_bn (const prob_bn* probs, state_bn state)
double NthLevel_bn (const level_bn* levels, state_bn state)
int GetChars_ns (const char* str, int index, unsigned short* dest, int num)
int NthChar_ns (const char* str, int index)
void SetNthState_bn (state_bn* states, int index, state_bn state)
void OptimizeDecisions_bn (const nodelist_bn* nodes)
nodelist_bn* NewNodeList_bn (int length, environ_ns* env)
double GetUndefDbl_ns()
double GetInfinityDbl_ns()
cdef extern from "NeticaEx.h":
void CompileNet_bn (net_bn* net)
double GetNodeBelief (char* node_name, char* state_name, net_bn* net)
void EnterFinding (char* node_name, char* state_name, net_bn* net)
int main_ex ()
node_bn* GetNode (char* node_name, net_bn* net)
void EnterFinding (char* node_name, char* state_name, net_bn* net)
void SetNodeFinding (node_bn* node, state_bn state)
void SetNodeValue (node_bn* node, double value)
double GetNodeBelief (char* node_name, char* state_name, net_bn* net)
void SetNodeProbs (node_bn* node, ...)
void SetNodeFuncState (node_bn* node, state_bn value, ...)
void SetNodeFuncReal (node_bn* node, double value, ...)
void SetNodeExper (node_bn* node, double value, ...)
void MakeProbsUniform (node_bn* node)
void GetNodeAllProbs (node_bn* node, prob_bn* probs, int num_entries)
bool_ns NextStates (state_bn* states, const nodelist_bn* nodes)
void PrintNodeList (nodelist_bn* nodes)
void RetractFindingsOfNodes (nodelist_bn* nodes, bool_ns do_consts_too)
int FindNodeNamed (const char* name, const nodelist_bn* nodes)
int IndexOfNodeInList (const node_bn* node, const nodelist_bn* nodes)
void RemoveOneNodeFromList (node_bn* node, nodelist_bn* nodes)
void RemoveNodeFromListIfThere (node_bn* node, nodelist_bn* nodes)
void RemoveNthNodeFast (int index, nodelist_bn* nodes)
void DeleteLink (node_bn* parent, node_bn* child)
void DeleteLinks (node_bn* parent, node_bn* child)
void DeleteLinksEntering (node_bn* child)
void SwitchNodeParent (node_bn* parent, node_bn* child, node_bn* new_parent)
void DeleteNodes (nodelist_bn* nodes)
bool_ns IsLinkDisconnected (int link_index, const node_bn* node)
nodelist_bn* TransferNodes (nodelist_bn* nodes, net_bn* new_net)
node_bn* DupNode (node_bn* node)
node_bn* DuplicateNode (node_bn* node, net_bn* new_net)
net_bn* DuplicateNet (net_bn* net, const char* newname)
net_bn* NetNamed (const char* name)
node_bn* FormCliqueWith (const nodelist_bn* nodes)
void AbsorbNode (node_bn* node)
void DeleteNetTables (net_bn* net)
void FadeCPTables (const nodelist_bn* nodes, double degree)
void PrintNeticaVersion ()
void PrintErrors ()
report_ns* NewError (environ_ns* env, int number, errseverity_ns severity, const char* mesg, ...)
void ClearErrors (environ_ns* env, errseverity_ns severity)
void SetNetUserString (net_bn* net, const char* fieldname, const char* str)
const char* GetNetUserString (net_bn* net, const char* fieldname)
void SetNetUserInt (net_bn* net, const char* fieldname, int num)
long GetNetUserInt (net_bn* net, const char* fieldname)
void SetNetUserNumber (net_bn* net, const char* fieldname, double num)
double GetNetUserNumber (net_bn* net, const char* fieldname)
void SetNodeUserString (node_bn* node, const char* fieldname, const char* str)
const char* GetNodeUserString (node_bn* node, const char* fieldname)
void SetNodeUserInt (node_bn* node, const char* fieldname, int num)
long GetNodeUserInt (node_bn* node, const char* fieldname)
void SetNodeUserNumber (node_bn* node, const char* fieldname, double num)
double GetNodeUserNumber (node_bn* node, const char* fieldname)
void PrintConfusionMatrix (tester_bn* tester, node_bn* node)
void CopyNodeRelation_bn (node_bn* dest, const node_bn* src, const nodelist_bn* parent_order_dest)
int MultiDimnIndex (const state_bn states[], const nodelist_bn* nodes)
double SizeCartesianProduct (const nodelist_bn* nodes)
node_bn* MapNode (const node_bn* node, const net_bn* dest_net)
nodelist_bn* MapNodeList (const nodelist_bn* nodes, const net_bn* dest_net)
nodelist_bn* MapNodeList1 (const nodelist_bn* oldorder, const nodelist_bn* oldnodes, const nodelist_bn* newnodes)
nodelist_bn* DisconnectNodeGroup (nodelist_bn* nodes)
char* NodeListToString (const nodelist_bn* nodes)
long CountCasesInFile (stream_ns* casefile)
int RemoveUnusedStates (node_bn* node)
int* MakeInverseOrdering (const int order[], int num, int invorder[])
void SetNodeStateNames (node_bn* node, ...)
void SetNodeFuncValue (node_bn* node, double value, ...)
double ExpectedValue (node_bn* node, double* stddev)
int PositionInNodeList (const node_bn* node, const nodelist_bn* nodes)
void RemoveNodeFromList (node_bn* node, nodelist_bn* nodes)
void SetNodeAllProbs (node_bn* node, const prob_bn* probs)
cdef extern from "stdarg.h":
ctypedef struct va_list:
pass
ctypedef struct fake_type:
pass
void va_start(va_list, void* arg)
void* va_arg(va_list, fake_type)
void va_end(va_list)
fake_type int_type "int"
cdef class Netica:
cdef environ_ns *env
cdef char mesg[600]
def __str__(self):
return self.mesg
def __repr__(self):
return self.mesg
def __unicode__(self):
return unicode(self.mesg)
cpdef NewNeticaEnviron_ns(self,char* license,Netica environ,char* locn):
if not license[0]:
licence=NULL
if not locn[0]:
locn=NULL
self.env=environ.env if type(environ)==Netica else NULL
self.env=NewNeticaEnviron_ns(license,self.env,locn)
return self
def InitNetica2_bn(self,Netica env,mesg=None):
cdef int res
if type(env)==Netica:
res = InitNetica2_bn (env.env,self.mesg)
else:
res = InitNetica2_bn (self.env,self.mesg)
if type(mesg)==bytearray:
while(len(mesg)):
mesg.pop()
for i in self.mesg:
mesg.append(i)
return res
def CloseNetica_bn(self,Netica env, mesg=None):
cdef int res
res = CloseNetica_bn(env.env, self.mesg)
if type(mesg)==bytearray:
while(len(mesg)):
mesg.pop()
for i in self.mesg:
mesg.append(i)
return res
def GetNeticaVersion_bn (self,Netica environ, _version = None):
cdef int res
cdef char* version
res = GetNeticaVersion_bn (environ.env if type(environ)==Netica else NULL,&version)
if type(_version)==bytearray:
while(len(_version)):
_version.pop()
for i in version:
_version.append(i)
return res
def ArgumentChecking_ns (self,checking_ns setting, Netica environ):
cdef checking_ns res
res=ArgumentChecking_ns (setting, environ.env if type(environ)==Netica else NULL)
return res
def SetLanguage_ns (self,Netica environ, char* language):
cdef char* res
res = SetLanguage_ns (environ.env if type(environ)==Netica else NULL,language)
return res
def LimitMemoryUsage_ns (self,double max_mem, Netica environ):
cdef double res
res = LimitMemoryUsage_ns (max_mem,environ.env if type(environ)==Netica else NULL)
return res
def SetEnvironUserData_ns (self,Netica environ, int kind, data):
SetEnvironUserData_ns (environ.env if type(environ)==Netica else NULL,kind,NULL if type(data)==None else <void*> data)
def GetEnvironUserData_ns (self,Netica environ, int kind):
cdef void* res
res = GetEnvironUserData_ns (environ.env if type(environ)==Netica else NULL,kind)
return <object>res
cdef report_ns* __GetError_ns (self,environ_ns* env, errseverity_ns severity, Report after):
return GetError_ns (env, severity, after.value)
def GetError_ns (self,Netica environ, errseverity_ns severity, after):
res=Report()
if type(after)==Report:
res.value = self.__GetError_ns (environ.env if type(environ)==Netica else NULL, severity, after)
else:
res.value = GetError_ns (environ.env if type(environ)==Netica else NULL, severity, NULL)
return res
def ErrorNumber_ns (self,Report error):
cdef int res
res = ErrorNumber_ns (error.value)
return res
def ErrorMessage_ns (self,Report error):
cdef char* res
res = ErrorMessage_ns (error.value)
return res
def ErrorSeverity_ns (self,Report error):
cdef errseverity_ns res
res = ErrorSeverity_ns (error.value)
return res
def ErrorCategory_ns (self,errcond_ns cond, Report error):
cdef bool_ns res
res = ErrorCategory_ns (cond, error.value)
return res
def ClearError_ns (self,Report error):
ClearError_ns (error.value)
def ClearErrors_ns (self,Netica environ, errseverity_ns severity):
ClearErrors_ns (environ.env if type(environ)==Netica else NULL, severity)
def NewError_ns (self,Netica environ, int number, errseverity_ns severity, mesg=None):
res = Report()
res.value = NewError_ns (environ.env if type(environ)==Netica else NULL,number, severity, self.mesg)
if type(mesg)==bytearray:
while(len(mesg)):
mesg.pop()
for i in self.mesg:
mesg.append(i)
return res
def TestFaultRecovery_ns (self,Netica environ, int test_num):
cdef int res
res = TestFaultRecovery_ns (environ.env if type(environ)==Netica else NULL, test_num)
return res
def UserAllowed_ns (self,Netica environ, int setting):
cdef int res
res = UserAllowed_ns (environ.env if type(environ)==Netica else NULL, setting)
return res
def NewFileStream_ns (self,char* filename, Netica environ,access=None):
cdef char* _access
if access:
_access=PyUnicode_AsUTF8(<PyObject*>access)
else:
_access=NULL
res = Stream()
res.value = NewFileStream_ns (filename, environ.env if type(environ)==Netica else NULL, _access)
if type(access)==bytearray:
while(len(access)):
access.pop()
for i in _access:
access.append(i)
# free(_access)
return res
def NewMemoryStream_ns (self,char* name, Netica environ, access=None):
cdef char* _access
if access:
_access = PyUnicode_AsUTF8(<PyObject*>access)
else:
NULL
res = Stream()
res.value = NewMemoryStream_ns (name, environ.env if type(environ)==Netica else NULL, _access)
if type(access)==bytearray:
while(len(access)):
access.pop()
for i in _access:
access.append(i)
# free(_access)
return res
def DeleteStream_ns (self,Stream _file):
DeleteStream_ns (_file.value if type(_file)==Stream else NULL)
def SetStreamPassword_ns (self,Stream stream, char* password):
SetStreamPassword_ns (stream.value if type(stream)==Stream else NULL, password)
def SetStreamContents_ns (self,Stream stream,_buffer, long length=0, bool_ns copy=True):
if not length:
length=len(_buffer)