Belle II Software development
test.py
1#!/usr/bin/env python3
2
3
10
11import numpy as np
12
13
14class State:
15 """
16 Test state
17 """
18
19 def __init__(self):
20 """ Constructor of the state object """
21
22 def __repr__(self):
23 """ Returns representation of this state"""
24 return 'State'
25
26
27def feature_importance(state):
28 """
29 Return a list containing the feature importances
30 """
31 print("Called feature importance")
32 return []
33
34
35def get_model(number_of_features, number_of_spectators, number_of_events, training_fraction, parameters):
36 """
37 Return default test model
38 """
39 print("Called get_model")
40 print(parameters)
41 return State()
42
43
44def load(obj):
45 """
46 Test load function
47 """
48 print("Called load")
49 print(obj)
50 return State()
51
52
53def apply(state, X):
54 """
55 Test apply function
56 """
57 print("Called apply")
58 print(state, X.shape)
59 p = np.zeros(len(X))
60 return np.require(p, dtype=np.float32, requirements=['A', 'W', 'C', 'O'])
61
62
63def begin_fit(state, Xtest, Stest, ytest, wtest, nBatches):
64 """
65 Test begin_fit function
66 """
67 print("Called begin_fit")
68 print(state, Xtest.shape, Stest.shape, ytest.shape, wtest.shape, nBatches)
69 return state
70
71
72def partial_fit(state, X, S, y, w, epoch, batch):
73 """
74 Test partial_fit function
75 """
76 print("Called partial_fit")
77 print(state, X.shape, S.shape, y.shape, w.shape, epoch, batch)
78 return True
79
80
81def end_fit(state):
82 """
83 Test end_fit function
84 """
85 print("Called end_fit")
86 print(state)
87 return "SerializedState"