'def MSEn(dataset_mus, Mobj, Scales=3, Methodx='coarse', RadNew=0, Plotx=False):
class MSobject:
x=(5,2,[3.2])
Mobj = MSobject(x)
dataset_mus=np.squeeze(dataset_mus)
Func2 = globals()[Methodx.lower()]
MSx = np.zeros(Scales)
for T in range(1,Scales+1):
print(' .', end='')
Temp = Func2(Sig,T)
MSx[T-1] = Temp2
CI = sum(MSx)
if np.any(np.isnan(MSx)):
print('Some entropy values may be undefined.')
if Plotx:
figure()
ax1 = axes()
ax1.plot(np.arange(1,Scales+1), MSx, color=(8/255, 63/255, 77/255), linewidth=3)
ax1.scatter(np.arange(1,Scales+1), MSx, 60, color=(1,0,1))
ax1.set_xlabel('Scale Factor',fontsize=12,fontweight='bold',color=(7/255, 54/255, 66/255))
ax1.set_ylabel('Entropy Value',fontsize=12,fontweight='bold',color=(7/255, 54/255, 66/255))
ax1.set_title('Multiscale %s (%s-graining method)'%(Mobj.Func.__name__,Methodx),
fontsize=16,fontweight='bold',color=(7/255, 54/255, 66/255))
show()
return MSx, CI
MSEn(dataset_mus,Mobj.x)'
error
'---------------------------------------------------------------------------
NameError Traceback (most recent call last)
/var/folders/pm/zc3gg3ts2x17sm0r11qd66k00000gn/T/ipykernel_89686/2723706301.py in
30 show()
31 return MSx, CI
---> 32 MSEn(dataset_mus,Mobj.x)
NameError: name 'Mobj' is not defined' '
Mobj needs to be defined.
Mobj= EH.MSobject('SampEn',m=2,r=0.15)
this will create a sample entropy object with the given parameters and then you can call MSen function to calculate multiscale entropy.
I am working on the same problem right now. But my code works for a large data but throws error for smalller data.
Related
This is my code:
p = range(0,3)
q = range(0,3)
d = range(0,3)
s = range(30,31)
P =range(0,1)
D = range(1,2)
Q = range(0,1)
lowest_aic= None
lowest_parm = None
lowest_param_seasonal = None
pdq = list(itertools.product(p, d, q))
seasonal_pdq = list(itertools.product(P,D,Q,s))
for param in pdq:
for param_seasonal in seasonal_pdq:
try:
mod = sm.tsa.statespace.SARIMAX(data,order=param,seasonal_order=param_seasonal)
results = mod.fit()
current_aic = results.aic
if (lowest_aic == None):
lowest_aic = results.aic
if (current_aic <= lowest_aic):
lowest_aic = current_aic
lowest_parm = param
lowest_param_seasonal = param_seasonal
#print('SARIMA{}x{} - AIC:{}'.format(param, param_seasonal, results.aic))
print('SARIMA{},{} - AIC:{}'.format(param, param_seasonal, results.aic))
except:
continue
print('SARIMA{}x{} - AIC:{}'.format(param, param_seasonal, results.aic))
syhat_sar_c = results.predict(len(df), len(df)+6, typ='levels',dynamic=False)
print(np.array(syhat_sar))
I am trying to implement a grid search for my SARIMA model.
I would like to know why try block is not getting executed, because of which it is throwing, UnboundLocal error.
It would be great if the explanation would be detailed.
This is the traceback I am getting when I run this code:
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-12-2669d247586e> in <module>()
35
36
---> 37 print('SARIMA{}x{} - AIC:{}'.format(param, param_seasonal, results.aic))
38 syhat_sar_c = results.predict(len(df), len(df)+6, typ='levels',dynamic=False)
39 print(np.array(syhat_sar))
NameError: name 'results' is not defined
There are three possibilities:
pdq is empty, so the outer for loop exits immediately and the try is never executed.
seasonal_pdq is empty, so the inner for loop exits immediately and the try is never executed.
The try is executed, but it terminates before the variable you're depending on has been bound.
The rudimentary debugging techniques you could use to narrow this down would be:
Print pdq to make sure it's not empty.
Print seasonal_pdq to make sure it's not empty.
Change the continue to a raise so that the exception is raised instead of ignored. That way you can see what it is and exactly what line it came from.
I'm using JupyterLab to run the script for analysing my data. In this script, called 'analysis.ipynb', I'm using a function out of the script 'def_readfb_dwd.py'. This function contained a little error (a wrong parameter 'conf_flag_fb_aeolus' was included) which I corrected. But the correction has not been adopted... when I run the analysis script again I got the same error message:
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-78-39237ed9c16d> in <module>
----> 1 data_dwd = read_multiple_files(file_list,date_list,time_list,channel)
2 print(channel + ': ' + data_str, + ' ---> data loaded')
~/PhD/code/functions/def_readfb_dwd.py in read_multiple_files(file_list, date_list, time_list, retrtype)
106
107 def read_multiple_files(file_list,date_list,time_list,retrtype):
--> 108 combined_data = readin_fb_files(file_list[0],date_list[0],time_list[0],retrtype)
109 if len(file_list)>1:
110 for f in range(1,len(file_list)):
~/PhD/code/functions/def_readfb_dwd.py in readin_fb_files(file, d, anatime, retrtype)
80 ### filter data for time and status-active
81 filter_retrtype = np.where((data['retrtype'] == retrtype))[0]
---> 82 filter_flags = np.where((data['r_state'] == 1) & (data['r_check'] == 32))[0]
83 filt_ind = np.intersect1d(filter_retrtype,filter_flags)
84 data['r_state']=data['r_state'][filt_ind]
NameError: name 'conf_flag_fb_aeolus' is not defined
What can I do that changes in scripts, which I import are taken on
How to debug "NameError: global name 'X' is not defined" in Python? I am pretty much new in Python. I am using jupyter_notebook with Python 2.7 to execute code. I am facing following error.
My code:
logFile = "NASAlog.txt"
def parseLogs():
parsed_logs=(sc
.textFile(logFile)
.map(parseApacheLogLine)
.cache())
access_logs = (parsed_logs
.filter(lambda s: s[1] == 1)
.map(lambda s: s[0])
.cache())
failed_logs = (parsed_logs
.filter(lambda s: s[1] == 0)
.map(lambda s: s[0]))
failed_logs_count = failed_logs.count()
if failed_logs_count > 0:
print 'Number of invalid logline: %d' % failed_logs.count()
for line in failed_logs.take(20):
print 'Invalid logline: %s' % line
print 'Read %d lines, successfully parsed %d lines, failed to parse %d lines' % (parsed_logs.count(), access_logs.count(), failed_logs.count())
return parsed_logs, access_logs, failed_logs
parsed_logs, access_logs, failed_logs = parseLogs()
ERROR
> NameError Traceback (most recent call last)
> <ipython-input-18-b365aa793252> in <module>()
> 24 return parsed_logs, access_logs, failed_logs
> 25
> ---> 26 parsed_logs, access_logs, failed_logs = parseLogs()
>
> <ipython-input-18-b365aa793252> in parseLogs()
> 2
> 3 def parseLogs():
> ----> 4 parsed_logs=(sc
> 5 .textFile(logFile)
> 6 .map(parseApacheLogLine)
>
> NameError: global name 'sc' is not defined
The problem is that you did never define sc. Therefore python can't find it. (Makes sense, doesn't it?)
Now there are several possible reasons:
- python is case-sensitive. Did you somewhere define SC instead of sc? ... Or Sc instead of sc?
You defined sc in another function (-> you defined it in a function outside parseLogs()). If you only define it there the variable will be local and just be available to the code inside the function. Add the line global sc to the first line of your function to make it accessible everywhere in you whole code.
You simply did not define sc.
I am working on an assignment for Coursera's Machine Learning: Regression course. I am using the kc_house_data.gl/ dataset and GraphLab Create. I am adding new variables to train_data and test_data that are combinations of old variables. Then I take the mean of all these variables. These are the variables I am adding:
bedrooms_squared = bedrooms * bedrooms
bed_bath_rooms = bedrooms*bathrooms
log_sqft_living = log(sqft_living)
lat_plus_long = lat + long
Here is my code:
train_data['bedrooms_squared'] = train_data['bedrooms'].apply(lambda x: x**2)
test_data['bedrooms_squared'] = test_data['bedrooms'].apply(lambda x: x**2)
# create the remaining 3 features in both TEST and TRAIN data
train_data['bed_bath_rooms'] = train_data.apply(lambda row: row['bedrooms'] * row['bathrooms'])
test_data['bed_bath_rooms'] = test_data.apply(lambda row: row['bedrooms'] * row['bathrooms'])
train_data['log_sqft_living'] = train_data['sqft_living'].apply(lambda x: log(x))
test_data['log_sqft_living'] = test_data['bedrooms'].apply(lambda x: log(x))
train_data['lat_plus_long'] = train_data.apply(lambda row: row['lat'] + row['long'])
train_data['lat_plus_long'] = train_data.apply(lambda row: row['lat'] + row['long'])
test_data['bedrooms_squared'].mean()
test_data['bed_bath_rooms'].mean()
test_data['log_sqft_living'].mean()
test_data['lat_plus_long'].mean()
This is the error I'm getting:
RuntimeError: Runtime Exception. Exception in python callback function evaluation:
ValueError('math domain error',):
Traceback (most recent call last):
File "graphlab\cython\cy_pylambda_workers.pyx", line 426, in graphlab.cython.cy_pylambda_workers._eval_lambda
File "graphlab\cython\cy_pylambda_workers.pyx", line 169, in graphlab.cython.cy_pylambda_workers.lambda_evaluator.eval_simple
File "<ipython-input-13-1cdbcd5f5d9b>", line 5, in <lambda>
ValueError: math domain error
I have no idea what this means. Any idea on what caused it and how I fix it? Thanks.
Your problem is that log is receiving a negative number.
log is defined only for numbers greater than zero.
You need to check your values.
Please add/learn exceptions to make your code more robust:
try:
train_data['log_sqft_living'] = train_data['sqft_living'].apply(lambda x: log(x))
test_data['log_sqft_living'] = test_data['bedrooms'].apply(lambda x: log(x))
train_data['lat_plus_long'] = train_data.apply(lambda row: row['lat'] + row['long'])
train_data['lat_plus_long'] = train_data.apply(lambda row: row['lat'] + row['long'])
test_data['bedrooms_squared'].mean()
test_data['bed_bath_rooms'].mean()
test_data['log_sqft_living'].mean()
test_data['lat_plus_long'].mean()
except e as Exception:
print "ERROR in function:", e
This error pops up when I run the code I currently have.
Note : I did not write the code, I am simply trying to understand what's going on so that I can port it to a newer version of TuLiP.
Traceback (most recent call last):
File "vms5.py", line 270, in <module>
states = [aut_state.state]
AttributeError: 'int' object has no attribute 'state'
Line 270 says :
states = [aut_state.state]
I tried looking for state and found this
Line 249 :
state = dict(temp = Tmax, w = 0, h = 0, b = Bmax, a = 0, c = 0, nw = 0)
and aut_state at Lines 259 and 260
aut = createAut(aut_file = autfile, varnames = env_vars.keys() + sys_disc_vars.keys())
aut_state = aut.findNextAutState(current_aut_state=None, env_state=state)
Other terms with aut
Line 47 :
autfile = testfile+'.aut'
and Lines 223-234
# Check realizability
realizability = jtlvint.checkRealizability(smv_file=smvfile, spc_file=spcfile, \
aut_file=autfile, verbose=3)
# Compute an automaton
jtlvint.computeStrategy(smv_file=smvfile, spc_file=spcfile, aut_file=autfile, \
priority_kind=3, verbose=3)
aut = automaton.Automaton(autfile, [], 3)
That's everything in the code that has aut related terms
If you want more info, please let me know
EDIT
I tried adding print(aut_state) before line 270 and got -1 as an answer.
So aut is an int. Ints don't have an attribute called state. Whatever set the variable aut, set it with an int. Looks like an error code to me. Look at the code for findNextAutState - what does it return when there are no more AutStates? -1?
Probably a condition check missing.
from the traceback it is clear that aut_state is an integer, and integer cannot have any attribute called state. Your main Code problem lies inside the createAut() which creates an aut object or inside the findNextAutState() function which returns aut_state.