-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsearch.py
66 lines (47 loc) · 1.63 KB
/
search.py
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
import torch
import numpy as np
device = torch.device("cuda:0" if (torch.cuda.is_available()) else "cpu")
def decrease(bestmodel):
'''
Code for decreasing constant values of inputs (scattering power) to "scan" all possible predicitons of
particle dimensions' sizes. Negative values of scatttering power are present as inputs
since despite the fact that model is not aware of scttering physics for all particles,
it can still produce efficient predictions for dimension sizes.
'''
bestmodel.eval()
expected = torch.ones(1,5)
threshold = 9
j=0
vals_arr = []
threshold_arr = []
while threshold> -2:
vals = expected
threshold = (0.1-0.0025*j)
true_x_np = threshold *np.ones((1,151))
true_x = torch.from_numpy( true_x_np.reshape(1,151) ).float()
expected = bestmodel(true_x.to(device)).view(1,-1)
vals_arr.append(expected.cpu().data.numpy())
threshold_arr.append(threshold)
vals_arr = np.array(vals_arr)
vals_arr = vals_arr.reshape(vals_arr.shape[0],-1)
threshold_arr = np.array(threshold_arr)
print(vals_arr.shape)
print(threshold_arr.shape)
return vals_arr, threshold_arr
def extract_positive(vals_arr, threshold_arr):
val_temp = []
threshold_temp= []
counter = 0;
main_val_matlab = []
main_tr_matlab = []
for i,row in enumerate(vals_arr):
if (row<1).any() == False:
val_temp.append(row)
threshold_temp.append( threshold_arr[i])
counter +=1
print(counter)
val_temp = np.array(val_temp)
val_temp.shape
threshold_temp = np.array(threshold_temp)
threshold_temp.shape
return val_temp, threshold_temp