Code. X, and y should be irrelevant..
ker = gp.kernels.RBF(input_dim=2,variance=torch.tensor(1.), lengthscale=torch.ones((2,)))
gpr = gp.models.GPModel(kernel=ker, X=x, y=y)
Input:
list(gpr.parameters())
Output:
[0]: [Parameter containing:
tensor(0., requires_grad=True),
Parameter containing:
tensor([0., 0.], requires_grad=True)]
The resulting tensors are 0. not 1. expected..
Related
I have my function:
function [result] = my_func(x,y)
result = y^2*(1-3*x)-3*y;
endfunction
Also, my vector with Ts, my function address and my initial variable x_0
load file_with_ts
# Add my limits as I also want to calculate those
# (all values in file_with_ts are within those limits.)
t_points = [-1, file_with_ts, 2]
myfunc = str2func("my_func")
x_0 = 0.9142
I am trying to execute the following line:
lsode_d1 = lsode(myfunc, x_0, t_points)
And expecting a result, but getting the following error:
INTDY-- T (=R1) ILLEGAL
In above message, R1 = 0.7987082301475D+00
T NOT IN INTERVAL TCUR - HU (= R1) TO TCUR (=R2)
In above, R1 = 0.8091168896311D+00 R2 = 0.8280400838323D+00
LSODE-- TROUBLE FROM INTDY. ITASK = I1, TOUT = R1
In above message, I1 = 1
In above message, R1 = 0.7987082301475D+00
error: lsode: invalid input detected (see printed message)
error: called from
main at line 20 column 10
Also, the variable sizes are:
x_0 -> 1x1
t_points -> 1x153
myfunc -> 1x1
I tried transposing the t_points vector
using #my_func instead of the str2func function
I tried adding multiple variables as the starting point (instead of x_0 I entered [x_0; x_1])
Tried changing my function header from my_func(x, y) to my_func(y, x)
Read the documentation and confirmed that my_func allows x to be a vector and returns a vector (whenever x is a vector).
EDIT: T points is the following 1x153 matrix (with -1 and 2 added to the beggining and the end respectively):
-4.9451e-01
-4.9139e-01
-4.7649e-01
-4.8026e-01
-4.6177e-01
-4.5412e-01
-4.4789e-01
-4.2746e-01
-4.1859e-01
-4.0983e-01
-4.0667e-01
-3.8436e-01
-3.7825e-01
-3.7150e-01
-3.5989e-01
-3.5131e-01
-3.4875e-01
-3.3143e-01
-3.2416e-01
-3.1490e-01
-3.0578e-01
-2.9267e-01
-2.9001e-01
-2.6518e-01
-2.5740e-01
-2.5010e-01
-2.4017e-01
-2.3399e-01
-2.1491e-01
-2.1067e-01
-2.0357e-01
-1.8324e-01
-1.8112e-01
-1.7295e-01
-1.6147e-01
-1.5424e-01
-1.4560e-01
-1.1737e-01
-1.1172e-01
-1.0846e-01
-1.0629e-01
-9.4327e-02
-8.0883e-02
-6.6043e-02
-6.6660e-02
-6.1649e-02
-4.7245e-02
-2.8332e-02
-1.8043e-02
-7.7416e-03
-6.5142e-04
1.0918e-02
1.7619e-02
3.4310e-02
3.3192e-02
5.2275e-02
5.5756e-02
6.8326e-02
8.2764e-02
9.5195e-02
9.4412e-02
1.1630e-01
1.2330e-01
1.2966e-01
1.3902e-01
1.4891e-01
1.5848e-01
1.7012e-01
1.8026e-01
1.9413e-01
2.0763e-01
2.1233e-01
2.1895e-01
2.3313e-01
2.4092e-01
2.4485e-01
2.6475e-01
2.7154e-01
2.8068e-01
2.9258e-01
3.0131e-01
3.0529e-01
3.1919e-01
3.2927e-01
3.3734e-01
3.5841e-01
3.5562e-01
3.6758e-01
3.7644e-01
3.8413e-01
3.9904e-01
4.0863e-01
4.2765e-01
4.2875e-01
4.3468e-01
4.5802e-01
4.6617e-01
4.6885e-01
4.7247e-01
4.8778e-01
4.9922e-01
5.1138e-01
5.1869e-01
5.3222e-01
5.4196e-01
5.4375e-01
5.5526e-01
5.6629e-01
5.7746e-01
5.8840e-01
6.0006e-01
5.9485e-01
6.1771e-01
6.3621e-01
6.3467e-01
6.5467e-01
6.6175e-01
6.6985e-01
6.8091e-01
6.8217e-01
6.9958e-01
7.1802e-01
7.2049e-01
7.3021e-01
7.3633e-01
7.4985e-01
7.6116e-01
7.7213e-01
7.7814e-01
7.8882e-01
8.1012e-01
7.9871e-01
8.3115e-01
8.3169e-01
8.4500e-01
8.4168e-01
8.5705e-01
8.6861e-01
8.8211e-01
8.8165e-01
9.0236e-01
9.0394e-01
9.2033e-01
9.3326e-01
9.4164e-01
9.5541e-01
9.6503e-01
9.6675e-01
9.8129e-01
9.8528e-01
9.9339e-01
Credits to Lutz Lehmann and PierU.
The problem lied in the array t_points not being a monotonous array. Adding a sort(t_points) before doing any calculations fixed the error.
I want to use mat file in another machine (mac to linux) and try to use changeFilePaths. According the online doc enter link description here
My code is as follows, gTruth.DataSource value doesn't change before and after changeFilePath, why?
matlab version 2022a update 3 is used.
>> load('groundTruthLidar.mat');
Warning: The data source for the following source names could not be loaded. C:\Source
> In groundTruthLidar.loadobj (line 635)
>> gTruth.DataSource
ans =
PointCloudSequenceSource with properties:
Name: "Point Cloud Sequence"
Description: "A PointCloud sequence reader"
SourceName: "C:\Source"
SourceParams: [1×1 struct]
SignalName: "Source"
SignalType: PointCloud
Timestamp: {[0 sec]}
NumSignals: 1
>> currentPathDataSource = "C:\Source";
>> newPathDataSource = fullfile(matlabroot, 'toolbox', 'lidar', 'lidardata');
>> alternativeFilePaths = {[currentPathDataSource newPathDataSource]};
>> unresolvedPaths = changeFilePaths(gTruth, alternativeFilePaths)
unresolvedPaths =
0×0 empty string array
>> gTruth.DataSource
ans =
PointCloudSequenceSource with properties:
Name: "Point Cloud Sequence"
Description: "A PointCloud sequence reader"
SourceName: "C:\Source"
SourceParams: [1×1 struct]
SignalName: "Source"
SignalType: PointCloud
Timestamp: {[0 sec]}
NumSignals: 1
‘alternativeFilePaths’
>> alternativeFilePaths
alternativeFilePaths =
1×2 string array
"C:\Source" "/Applications/MATLAB_R2022a.app/too…"
>> dir(alternativeFilePaths(2))
. lidarLabeler
.. lidardata_VoxelLabels.mat
Contents.m pretrainedPointPillarsDetector.mat
PandasetLidarData.pcd sampleWPILabels.mat
fullParkingLotData.mat scene_data.mat
hesaiFileReaderConfiguration scene_target_reflectances.mat
highwayScene.pcd segmatchMapFullParkingLot.mat
las velodyneSensorBeamAngles.mat
lcc
I am trying to run a hyperparameters optimization with Talos. As I have a lot of parameters to test, I want to use a 'grid_downsample' argument that will select 30% of all possible hyperparameters combinations. However when I run my code I get: TypeError: __init__() got an unexpected keyword argument 'grid_downsample'
I tested the code below without the 'grid_downsample' option and with less hyperparameters.
#load data
data = pd.read_csv('data.txt', sep="\t", encoding = "latin1")
# split into input (X) and output (y) variables
Y = np.array(data['Y'])
data_bis = data.drop(['Y'], axis = 1)
X = np.array(data_bis)
p = {'activation':['relu'],
'optimizer': ['Nadam'],
'first_hidden_layer': [12],
'second_hidden_layer': [12],
'batch_size': [20],
'epochs': [10,20],
'dropout_rate':[0.0, 0.2]}
def dnn_model(x_train, y_train, x_val, y_val, params):
model = Sequential()
#input layer
model.add(Dense(params['first_hidden_layer'], input_shape=(1024,)))
model.add(Dropout(params['dropout_rate']))
model.add(Activation(params['activation']))
#hidden layer 2
model.add(Dense(params['second_hidden_layer']))
model.add(Dropout(params['dropout_rate']))
model.add(Activation(params['activation']))
# output layer with one node
model.add(Dense(1))
model.add(Activation(params['activation']))
# Compile model
model.compile(loss='binary_crossentropy', optimizer=params['optimizer'], metrics=['accuracy'])
out = model.fit(x_train, y_train,
batch_size=params['batch_size'],
epochs=params['epochs'],
validation_data=[x_val, y_val],
verbose=0)
return out, model
scan_object = ta.Scan(X, Y, model=dnn_model, params=p, experiment_name="test")
reporting = ta.Reporting(scan_object)
report = reporting.data
report.to_csv('./Random_search/dnn/report_talos.txt', sep = '\t')
This code works well. If I change the scan_object as the end to: scan_object = ta.Scan(X, Y, model=dnn_model, grid_downsample=0.3, params=p, experiment_name="test"), it gives me the error: TypeError: __init__() got an unexpected keyword argument 'grid_downsample' while I was expecting to have the same results format as a normal grid search but with less combinations. What am I missing? Did the name of the argument change? I'm using Talos 0.6.3 in a conda environment.
Thank you!
might be too late for you now but they've switched it to fraction_limit. It would give this for you
scan_object = ta.Scan(X, Y, model=dnn_model, params=p, experiment_name="test", fraction_limit = 0.1)
Sadly, the doc isn't well updated
Check out their examples on GitHub:
https://github.com/autonomio/talos/blob/master/examples/Hyperparameter%20Optimization%20with%20Keras%20for%20the%20Iris%20Prediction.ipynb
Let we have vector in Matlab such as
V =
0.000178395155017
0.000213248167386
0.000453830296775
*0.000954267024225
0.001985203786879
0.002752603423106
0.004236131760631
0.005323800592906
0.004742807895286
0.005770068613768
0.006502644472601
0.007193873735489
0.006799579314313
0.007976014911026
0.007799267839386
0.008907651205854
0.009190413742866
0.008776108424259
0.008578897868764
0.009250162682559
0.008646692914164
0.008053809730819
0.007451047998031
0.006729120942615
0.005979207722644
0.007134289275269
0.005186062958380
0.005902382106719
0.007762189959679
0.008579238141806
0.009485819832702
0.009780236553648
0.010538511758940
0.012865379338644
0.011390556215603
0.010804154725939
0.010290545066940
0.009868360169125
0.009357083973682
0.008724843328595
0.008560695909341
0.008784388594649
0.008739349797176
0.008670604330509
0.008753566233007
0.008490628616888
0.008003101497979
0.008389140601319
0.007282172470936
0.006743970005005
0.006452902620905
0.005895958422668
0.006326020573140
0.005740103704853
0.005142834616900
0.004407465481546
0.003835738957490
0.004510955842245
0.003693705366274
0.002915993815608
0.002889010498571
0.003093844935832
0.004282403818479
0.003970929347537
0.002819774971736
0.003095369398698
0.002920594268954
0.002431265415582
0.001949299679935
0.001496954638334
0.001096892239592
0.001092281820070
0.000790749599802
0.000893827364410
0.001334675844874
0.001196368539888
0.001160349994386
0.001020290171146
0.001112407234178
0.001747377249787
0.002765678114897
0.003478849585666
0.005355127628032
0.004986389269550
0.005947847852449
0.006157789251547
0.006181425650566
0.006194151127049
0.006269927746287
0.006769754494212
0.007712318414790
0.008651586166082
0.008790606282214
0.009736113450469
0.011185160343747
0.012691072774672
0.010504478607987
0.014389683527318
0.014831212205190
0.028483974800043
0.011080767592010
0.011092374038746
0.012487511417703
0.013592769613900
0.023109284793639
0.011965905202027
0.012215762791363
0.013202467569807
0.011692397524803
0.011053425496442
0.010772141978943
0.010246937424879
0.0099733483767118
0.009945578183562
0.010512885752603
0.009531902580105
0.008066298613627
0.007407338182258
0.007934227536212
0.008839106853309
0.007141630457420
0.005890234651479
0.005777682702918
0.005975075824875
0.007650395349746
0.007857392419299
0.005786229253901
0.005200025773704
0.004125852007666
0.004066689824078
0.003581520984740
0.001457233291953
0.001322814038819
0.001253430603776
0.002493349764335
0.001702719375177
0.001556075727362
0.001200788268232
0.000940090552841
0.002078710051336
0.001014764365464
0.000954943700664
0.001276066704394
0.001359265944949
0.001204978086943
0.001593370287575
0.001547390763560
0.000930577956978
0.000916566445246
0.000546925307518
0.013565059409590
0.001282356857566
0.015602976997836
0.001499511920717
0.001586946634746
0.014156830819098
0.000291360243454
0.000429438521866
0.000462155358170
0.000362561191605
0.000657801010925
0.000593844882183
0.000609582362382
0.000310044384822
0.000342618178403
0.000282871074224
0.000314326548349
0.000204414827855
0.000337206866696
0.000532099888764
0.001193470342198
0.001296110099774
0.000872141517716
0.000700042872179
0.000881365833141
0.000373364170668
0.000425611062469
0.001421790419507
0.000852308546181
0.000815064422325
0.000504599352342
0.000700524140014
0.000870732973155
0.000714061606598
0.001035552251181
0.001149954823243
0.001055911091689
0.001199405112898
0.001783769543970
0.002409901173348
0.003498367375372
0.003703495953811
0.006277776686302
0.011652755634052
0.010083799009042
0.040863796019376
0.013614001128299
0.011042432683334
0.015305185452370
0.012711371813255
0.016268067330822
0.017370177368730
0.019331483583318
0.014673338103928
0.017693568446981
0.016892965150834
0.014088831405978
0.017200144763667
0.014169123504048
0.010078177083794
0.014268458659556
0.011690206086017
0.006562739851251
0.016466509298505
0.015914670918691
0.005624098695020
0.017555623339083
0.013692853335518
0.004491863547507
0.015326207984803
0.014740709288865
0.003199262301369
0.013665227028721
0.052745092682123
0.029889776608225
0.008659506247240
0.008589034126194
0.007785146195475
0.007151058968527
0.006980966929187
0.005799220068642
0.005386071463278
0.004896307509138
0.004818382921265
0.004623210359464
0.004383594039787
0.003923666862792
0.003524680860004
0.003014782806900
0.002558267907671
0.002794987126812
0.003018175443714
0.003166769934104
0.004138527203301
0.004310037290568
0.004610838173675
0.004947713276471
0.005083932336596
0.005236700123762
0.004687780786133
0.004564827415894
0.004302650724049
0.004270824001320
0.003937584195932
0.003911947276786
0.003620705359817
0.003151576407325
0.002751470077629
0.002669908472863
0.002232914262935
0.002069299781104
0.001979860796735
0.001601476811607
0.000301142580668
0.000321068102647
0.000390207925071
0.000210753154473
0.000387358708178
0.000241971967384
0.000366525972307
0.000619750196280
0.000412347959310
0.000544608934404
0.001311532428278
0.000736536458620
0.000523889409829
0.000492076015774
0.000297176544828
0.000195452121510
0.000292051729488
0.000759425298714
0.004267105657429
0.000192598592911
0.000235881092079
0.000209623369819
0.000160795350619
0.000118611207140
0.000253937140734
0.000229140021426
0.000132672582131
0.000185947357453
0.000336849580242
0.000161741284909
0.000212296295172
0.000129317114703
0.000078122221464
0.000139606283922
0.000074030291037
0.000273018975900
0.000084307182558
Our aim is to split it into some other vectors.
Th criteria to splitting is if:
1- There is a change in element V(i) and V(i+1)of at least 10e-1.
It store the indices into a new vector W and if:
2- their differences in indices is larger than 30, i.e., W(j) - W(j+1) > 30.
If these both conditions are satisfied then the vector would be split till the index i. otherwise would be left.
For example in the given vector, the output indices should be as:
[4, 75, 185]
where the there would be 4 vectors:
V1 = [1:4]
V2 = [4:75]
v3 = [75:185]
V4 = [185:300]
What would you think about choosing a tolerance or having a criteria?
Any idea is really appreciated.
I guess what you want is:
V = [0.0003,0.0008,0.0019,0.0027,0.0034,0.0103,0.0110,0.0106,0.0113,0.0134,0.0143,0.0148,0.0152,0.0156,0.00166,0.00172,0.0174,0.0195,0.0193,0.000195,0.00021]
digit = 2;
output = accumarray(cumsum(logical([0; diff(floor(10^digit*V(:)))]))+1,V,[],#(x) {x})
gives you an cell array.
output =
[5x1 double]
[9x1 double]
[2x1 double]
[3x1 double]
[2x1 double]
some explainations:
%// get the important digit
digs = floor(10^digit*V(:));
%// see where it changes
d = [0; diff(digs)];
%// convert to 0s and 1s and cumsum them up
subs = cumsum(logical(d))+1;
%// to get the subs for accumarray
output = accumarray(subs,V,[],#(x) {x})
After importing this data file from Matlab with scipy.io.loadmat, things appeared to work fine until we tried to calculate the conditioning number of one of the matrixes within.
Here's the minimum amount of code that reproduces for us:
import scipy
import numpy
stuff = scipy.io.loadmat("dati-esercizio1.mat")
numpy.linalg.cond(stuff["A"])
Here's the extended stacktrace courtesy of iPython:
In [3]: numpy.linalg.cond(A)
---------------------------------------------------------------------------
LapackError Traceback (most recent call last)
/snip/<ipython-input-3-15d9ef00a605> in <module>()
----> 1 numpy.linalg.cond(A)
/snip/python2.7/site-packages/numpy/linalg/linalg.py in cond(x, p)
1409 x = asarray(x) # in case we have a matrix
1410 if p is None:
-> 1411 s = svd(x,compute_uv=False)
1412 return s[0]/s[-1]
1413 else:
/snip/python2.7/site-packages/numpy/linalg/linalg.py in svd(a, full_matrices, compute_uv)
1313 work = zeros((lwork,), t)
1314 results = lapack_routine(option, m, n, a, m, s, u, m, vt, nvt,
-> 1315 work, -1, iwork, 0)
1316 lwork = int(work[0])
1317 work = zeros((lwork,), t)
LapackError: Parameter a has non-native byte order in lapack_lite.dgesdd
All obvious ideas (like flattening and reshaping the matrix or recreating the matrix from scratch reassigning it element by element) failed. How can I want to massage the data, then, in order to make it more agreeable with numpy?
It's a bug, fixed some time ago: https://github.com/numpy/numpy/pull/235
Workaround:
np.linalg.cond(stuff['A'].newbyteorder('='))
This works for me:
In [33]: stuff = loadmat('dati-esercizio1.mat')
In [34]: a = stuff['A']
In [35]: try: np.linalg.cond(a)
....: except: print "Fail!"
Fail!
In [36]: b = np.array(a, dtype='>d')
In [37]: np.linalg.cond(b)
Out[37]: 62493201976.673141
In [38]: np.all(a == b) # Verify they hold the same data.
Out[38]: True
Apparently it's something wrong with the byte order (endianness?) of each number in the resulting ndarray and not just with the ndarray object itself.
Something like this but more elegant should do the trick:
n, m = A.shape()
B = numpy.empty_like(A)
for i in xrange(n):
for j in xrange(m):
B[i,j] = float(A[i,j])
del A
B = A
print numpy.linalg.cond(A) # 62493210091.354507
(For some reason an in-place replacement still gives that error - so there's something wrong with the byte order of the whole object, too.)