Stack bar-chart intersected between each other - python

I have the following code for the stack bar chart
cols = ['Bug Prediction','Traceability','Security', 'Program Generation & Repair',
'Performance Prediction','Code Similarity & Clone Detection',
'Code Navigation & Understanding', 'Other_SE']
count_ANN = [2.0,0.0,1.0,0.0,0.0,3.0,5.0,1.0]
count_CNN = [1.0,0.0,5.0,0.0,1.0,4.0,4.0,0.0]
count_RNN = [1.0,0.0,3.0,1.0,0.0,4.0,7.0,2.0]
count_LSTM =[3.0,0.0,5.0,3.0,1.0,9.0,15.0,1.0]
count_GNN = [0.0,0.0,1.0,0.0,0.0,3.0,3.0,3.0]
count_AE = [0.0,0.0,1.0,3.0,0.0,6.0,11.0,0.0]
count_AM = [2.0,0.0,1.0,4.0,1.0,4.0,15.0,1.0]
count_other =[1.0,0.0,2.0,2.0,0.0,1.0,3.0,0.0]
b_RNN = list(np.add(count_ANN,count_CNN))
b_LSTM = list(np.add(np.add(count_ANN,count_CNN),count_RNN))
b_AE = list(np.add(np.add(np.add(count_ANN,count_CNN),count_RNN),count_AE))
b_GNN = list(np.add(b_AE,count_GNN))
b_others = list(np.add(b_GNN,count_other))
plt.bar(cols,count_ANN,0.4,label = "ANN")
plt.bar(cols,count_CNN,0.4,bottom=count_ANN,label = "CNN")
plt.bar(cols,count_RNN,0.4,bottom=b_RNN,label = "RNN")
plt.bar(cols,count_LSTM,0.4,bottom =b_LSTM, label = "LSTM")
plt.bar(cols,count_AE,0.4,bottom=b_AE,label = "Auto-Encoder")
plt.bar(cols,count_GNN,0.4,bottom=b_GNN,label = "GNN")
plt.bar(cols,count_other,0.4,bottom=b_others,label = "Others")
#ax.bar(cols, count)
plt.xticks(np.arange(len(cols))+0.1,cols)
fig.autofmt_xdate()
plt.legend()
plt.show()
Then the output for this is overlapped stacks as in the following figure

The specific problem is that b_AE is calculated wrong. (Also, there is a list called count_AM for which there is no label).
The more general problem, is that calculating all these values "by hand" is very prone to errors and difficult to adapt when there are changes. It helps to write things in a loop.
The magic of numpy's broadcasting and vectorization lets you initialize bottom as a single zero, and then use numpy's adding to add the counts.
To have a bit neater x-axis, you can put the individual words on separate lines. Also, plt.tight_layout() tries to make sure all text fits nicely into the plot.
import matplotlib.pyplot as plt
import numpy as np
cols = ['Bug Prediction', 'Traceability', 'Security', 'Program Generation & Repair',
'Performance Prediction', 'Code Similarity & Clone Detection',
'Code Navigation & Understanding', 'Other_SE']
count_ANN = [2.0, 0.0, 1.0, 0.0, 0.0, 3.0, 5.0, 1.0]
count_CNN = [1.0, 0.0, 5.0, 0.0, 1.0, 4.0, 4.0, 0.0]
count_RNN = [1.0, 0.0, 3.0, 1.0, 0.0, 4.0, 7.0, 2.0]
count_LSTM = [3.0, 0.0, 5.0, 3.0, 1.0, 9.0, 15.0, 1.0]
count_GNN = [0.0, 0.0, 1.0, 0.0, 0.0, 3.0, 3.0, 3.0]
count_AE = [0.0, 0.0, 1.0, 3.0, 0.0, 6.0, 11.0, 0.0]
count_AM = [2.0, 0.0, 1.0, 4.0, 1.0, 4.0, 15.0, 1.0]
count_other = [1.0, 0.0, 2.0, 2.0, 0.0, 1.0, 3.0, 0.0]
all_counts = [count_ANN, count_CNN, count_RNN, count_LSTM, count_GNN, count_AE, count_AM, count_other]
all_labels = ["ANN", "CNN", "RNN", "LSTM", "GNN", "Auto-Encoder", "AM", "Others"]
cols = ["\n".join(c.split(" ")) for c in cols]
cols = [c.replace("&\n", "& ") for c in cols]
bottom = 0
for count_i, label in zip(all_counts, all_labels):
plt.bar(cols, count_i, 0.4, bottom=bottom, label=label)
bottom += np.array(count_i)
# plt.xticks(np.arange(len(cols)) + 0.1, cols)
plt.tick_params(axis='x', labelrotation=45, length=0)
plt.legend()
plt.tight_layout()
plt.show()
PS: To have the bars in the same order as the legend, you could draw them starting from the top:
bottom = np.sum(all_counts, axis=0)
for count_i, label in zip(all_counts, all_labels):
bottom -= np.array(count_i)
plt.bar(cols, count_i, 0.4, bottom=bottom, label=label)

Related

Problem Fitting a Residence Time Distribution Data

I am trying to fit Resident Time Distribution (RTD) Data. RTD is typically skewed distribution. I have built a simple code that takes this non equally space-time data set from the RTD.
Data Sett
timeArray = [0.0, 0.5, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 12.0, 14.0]
concArray = [0.0, 0.6, 1.4, 5.0, 8.0, 10.0, 8.0, 6.0, 4.0, 3.0, 2.2, 1.5, 0.6, 0.0]
To fit the data I have been using python curve_fit function
parameters, covariance = curve_fit(nCSTR, time, conc, p0=guess)
and different sets of models (ex. CSTR, Sine, Gauss) to fit the data. However, no success so far.
The RTD data that I have correspond to a CSTR and there is an equation that model very accurate this type of behavior.
#Generalize nCSTR model
y = (( (np.power(x/tau,n-1)) * np.power(n,n) ) / (tau * math.gamma(n)) ) * np.exp(-n*x/tau)
As a separate note: from the Generalized nCSTR model I am using gamma instead of (n-1)! factorial terms because of the complexities of the code trying to deal with decimal values in factorials terms.
This CSTR model should be the one fitting the data without problem but for some reason is not able to do so. The outcome after executing my code:
timeArray = [0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5, 7.0, 7.5, 8.0, 8.5, 9.0, 9.5, 10.0, 10.5, 11.0, 11.5, 12.0, 12.5, 13.0, 13.5, 14.0]
concArray = [0.0, 0.6, 1.4, 2.6, 5.0, 6.5, 8.0, 9.0, 10.0, 9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.5, 3.0, 2.5, 2.2, 1.8, 1.5, 1.2, 1.0, 0.8, 0.6, 0.5, 0.3, 0.1, 0.0]
#Recast time and conc into numpy arrays
time = np.asarray(timeArray)
conc = np.asarray(concArray)
plt.plot(time, conc, 'o')
def nCSTR(x, tau, n):
y = (( (np.power(x/tau,n-1)) * np.power(n,n) ) / (tau * math.gamma(n)) ) * np.exp(-n*x/tau)
return y
guess = [1, 12]
parameters, covariance = curve_fit(nCSTR, time, conc, p0=guess)
tau = parameters[0]
n = parameters[1]
y = np.arange(0.0, len(time), 1.0)
for i in range(len(timeArray)):
y[i] = (( (np.power(time[i]/tau,n-1)) * np.power(n,n) ) / (tau * math.gamma(n)) ) * np.exp(-n*time[i]/tau)
plt.plot(time,y)
is this plot Fitting Output
I know I am missing something and any help will be well appreciated. The model has been well known for decades so it should not be related to the equation. I did some dummy data to confirm that the equation is written correctly and the output was the same type of profile that I am looking for. In that end, the equestion is fine.
import numpy as np
import math
t = np.arange(0.0, 10.5, 0.5)
tau = 2
n = 5
y = np.arange(0.0, len(t), 1.0)
for i in range(len(t)):
y[i] = (( (np.power(t[i]/tau,n-1)) * np.power(n,n) ) / (tau * math.gamma(n)) ) * np.exp(-n*t[i]/tau)
print(y)
plt.plot(t,y)
CSTR profile with Dummy Data (image)
If anyone is interested in the theory behind it I recommend any reading related to Tank In Series (specifically CSTR) Fogler has a great book about this topic.
I think that the main problem is that your model does not allow for an overall scale factor or that your data may not be normalized as you expect.
If you'll permit me to convert your curve-fitting program to use lmfit (I am a lead author), you might do:
import numpy as np
from scipy.special import gamma
import matplotlib.pyplot as plt
from lmfit import Model
timeArray = [0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5, 7.0, 7.5, 8.0, 8.5, 9.0, 9.5, 10.0, 10.5, 11.0, 11.5, 12.0, 12.5, 13.0, 13.5, 14.0]
concArray = [0.0, 0.6, 1.4, 2.6, 5.0, 6.5, 8.0, 9.0, 10.0, 9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.5, 3.0, 2.5, 2.2, 1.8, 1.5, 1.2, 1.0, 0.8, 0.6, 0.5, 0.3, 0.1, 0.0]
#Recast time and conc into numpy arrays
time = np.asarray(timeArray)
conc = np.asarray(concArray)
plt.plot(time, conc, 'o', label='data')
def nCSTR(x, scale, tau, n):
"""scaled CSTR model"""
z = n*x/tau
return scale * np.exp(-z) * z**(n-1) * (n/(tau*gamma(n)))
# create a Model for your model function
cmodel = Model(nCSTR)
# now create a set of Parameters for your model (note that parameters
# are named using your function arguments), and give initial values
params = cmodel.make_params(tau=3, scale=10, n=10)
# since you have `xxx**(n-1)`, setting a lower bound of 1 on `n`
# is wise, otherwise you would have to handle complex values
params['n'].min = 1
# now fit the model to your `conc` data with those parameters
# (and also passing in independent variables using `x`: the argument
# name from the signature of the model function)
result = cmodel.fit(conc, params, x=time)
# print out a report of the results
print(result.fit_report())
# you do not need to construct the best fit yourself, it is in `result`:
plt.plot(time, result.best_fit, label='fit')
plt.legend()
plt.show()
This will print out a report that includes statistics and uncertainties:
[[Model]]
Model(nCSTR)
[[Fit Statistics]]
# fitting method = leastsq
# function evals = 29
# data points = 29
# variables = 3
chi-square = 2.84348862
reduced chi-square = 0.10936495
Akaike info crit = -61.3456602
Bayesian info crit = -57.2437727
R-squared = 0.98989860
[[Variables]]
scale: 49.7615649 +/- 0.81616118 (1.64%) (init = 10)
tau: 5.06327482 +/- 0.05267918 (1.04%) (init = 3)
n: 4.33771512 +/- 0.14012112 (3.23%) (init = 10)
[[Correlations]] (unreported correlations are < 0.100)
C(scale, n) = -0.521
C(scale, tau) = 0.477
C(tau, n) = -0.406
and generate a plot of

Pandas Dataframe plot method not interpreting color parameter properly

I have the following colors variable that contains the RGBA values of the colours I would like my bar graphs to be.
colors = [(1.0, 0.0, 0.0, 1.0),
(0.9625172106584595, 0.0, 0.0, 1.0),
(0.8426095407791366, 0.0, 0.0, 1.0),
(0.7803353041224589, 0.0, 0.0, 1.0),
(0.7778812667044626, 0.0, 0.0, 1.0),
(0.7527658540536163, 0.0, 0.0, 1.0),
(0.7322264517696606, 0.0, 0.0, 1.0),
(0.6348343727221187, 0.0, 0.0, 1.0),
(0.5364622985340568, 0.0, 0.0, 1.0),
(0.5, 0.0, 0.0, 1.0)]
However, it seems like all of the bar graphs are only taking the colour of the first value
reg_graph = reg_df.plot(kind="barh",figsize=(10,6),color=colors)
reg_graph.set_title("Number of records by region",fontsize=15)
Any ideas on how to resolve this issue?
-------- EDIT ---------
I have included more code from my jupyter notebook
reg_df = pd.DataFrame({"Records per region":df["Region"].value_counts()})
reg_df["Region Name"] = reg_df.index.to_series().map(codes_to_names_map["Region"])
#reg_df = reg_df.set_index("Region Name")
reg_df = reg_df.sort_values("Records per region")
reg_df
#Applying a colour gradient for better data visualization
max_value = reg_df["Records per region"].max()
min_value = reg_df["Records per region"].min()
def calculate_color(value):
MAX_COLOR = (0.5,0,0)
MIN_COLOR = (1,0,0)
diff_in_color = tuple(map(lambda i, j: i - j, MAX_COLOR, MIN_COLOR))
calculate_diff = tuple((value-min_value)/(max_value-min_value) * i for i in diff_in_color)
return tuple(map(lambda i, j: i + j, calculate_diff, MIN_COLOR))
colors = [i for i in reg_df["Records per region"].apply(calculate_color)]
colors
# Plotting the bar graph
reg_graph = reg_df.plot(kind="barh",figsize=(10,6),color=colors)
reg_graph.set_title("Number of records by region",fontsize=15)
This final bit of code produces the graph in red despite the colors array being different RGB values.

H5PY - How to store many 2D arrays of different dimensions

I would like to organize my collected data (from computer simulations) into a hdf5 file using Python.
I measured positions and velocities [x,y,z,vx,vy,vz] of all atoms within a certain space region over many time steps. The number of atoms, of course, varies from time step to time step.
A minimal example could look as follows:
[
[ [x1,y1,z1,vx1,vy1,vz1], [x2,y2,z2,vx2,vy2,vz2] ],
[ [x1,y1,z1,vx1,vy1,vz1], [x2,y2,z2,vx2,vy2,vz2], [x3,y3,z3,vx3,vy3,vz3] ]
]
(2 time steps,
first time step: 2 atoms,
second time step: 3 atoms)
My idea was to create a hdf5 dataset within Python which stores all the information. At each time step it should store a 2d array of alls positions/velocities of all atoms, i.e.
dataset[0] = [ [x1,y1,z1,vx1,vy1,vz1], [x2,y2,z2,vx2,vy2,vz2] ]
dataset[1] = [ [x1,y1,z1,vx1,vy1,vz1], [x2,y2,z2,vx2,vy2,vz2], [x3,y3,z3,vx3,vy3,vz3] ].
The idea is clear, I think. However, I struggle with the definition of the correct data type of the data set with varying array length.
My code looks like this:
import numpy as np
import h5py
file = h5py.File ('file.h5','w')
columnNo = 6
rowtype = np.dtype("%sfloat32" % columnNo)
dt = h5py.special_dtype( vlen=np.dtype(rowtype) )
dataset = file.create_dataset("dset", (2,), dtype=dt)
print dataset.value
testarray = np.array([[1.,2.,3.,2.,3.,4.],[1.,2.,3.,2.,3.,4.]])
print testarray
dataset[0] = testarray
print dataset[0]
This, however, does not work. When I run the script I get the error message "AttributeError: 'float' object has no attribute 'dtype'."
It seems that my defined dtype is wrong.
Does anybody see how it should be defined correctly?
Thanks very much,
Sven
The error in your case is buried, though it is clear it occurs when trying to assign the testarray to the dataset:
Traceback (most recent call last):
File "stack41465480.py", line 26, in <module>
dataset[0] = testarray
File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper (/build/h5py-GhwtGD/h5py-2.6.0/h5py/_objects.c:2577)
...
File "h5py/_conv.pyx", line 712, in h5py._conv.ndarray2vlen (/build/h5py-GhwtGD/h5py-2.6.0/h5py/_conv.c:6171)
AttributeError: 'float' object has no attribute 'dtype'
I'm not skilled with the special_dtype and vlen, but I was able to write a numpy structured arrays to h5py.
import numpy as np
import h5py
file = h5py.File ('file.h5','w')
columnNo = 6
# rowtype = np.dtype("%sfloat32" % columnNo)
rowtype = np.dtype([('f0', '<f4',(6,))])
dt = h5py.special_dtype( vlen=np.dtype(rowtype) )
print('rowtype',rowtype)
print('dt',dt)
dataset = file.create_dataset("dset", (2,), dtype=rowtype)
print('value')
print(dataset.value[0])
arr = np.ones((2,),dtype=rowtype)
print(repr(arr))
dataset[0] = arr[0]
print(dataset.value)
testarray = np.array([([1.,2.,3.,2.,3.,4.],),([2.,3.,4.,1.,2.,3.],)], dtype=rowtype)
print(repr(testarray))
dataset[1] = testarray[1]
print(dataset.value)
print(dataset.value['f0'])
producing
1316:~/mypy$ python3 stack41465480.py
rowtype [('f0', '<f4', (6,))]
dt object
value
([0.0, 0.0, 0.0, 0.0, 0.0, 0.0],)
array([([1.0, 1.0, 1.0, 1.0, 1.0, 1.0],), ([1.0, 1.0, 1.0, 1.0, 1.0, 1.0],)],
dtype=[('f0', '<f4', (6,))])
[([1.0, 1.0, 1.0, 1.0, 1.0, 1.0],) ([0.0, 0.0, 0.0, 0.0, 0.0, 0.0],)]
array([([1.0, 2.0, 3.0, 2.0, 3.0, 4.0],), ([2.0, 3.0, 4.0, 1.0, 2.0, 3.0],)],
dtype=[('f0', '<f4', (6,))])
[([1.0, 1.0, 1.0, 1.0, 1.0, 1.0],) ([2.0, 3.0, 4.0, 1.0, 2.0, 3.0],)]
[[ 1. 1. 1. 1. 1. 1.]
[ 2. 3. 4. 1. 2. 3.]]
Thanks for the quick answer. It helped a lot.
If I now simply change the data type of the data set to
dtype = dt,
I get what I would like to have.
Here, the Python code (for completeness):
import numpy as np
import h5py
file = h5py.File ('file.h5','w')
columnNo = 6
rowtype = np.dtype([('f0', '<f4',(6,))])
dt = h5py.special_dtype( vlen=np.dtype(rowtype) )
print('rowtype',rowtype)
print('dt',dt)
dataset = file.create_dataset("dset", (2,), dtype=dt)
# print('value')
# print(dataset.value[0])
arr = np.ones((3,),dtype=rowtype)
# print(repr(arr))
dataset[0] = arr
# print(dataset.value)
testarray = np.array([([1.,2.,3.,2.,3.,4.],),([2.,3.,4.,1.,2.,3.],)], dtype=rowtype)
# print(repr(testarray))
dataset[1] = testarray
print(dataset.value)
for i in range(2): print dataset[i]
And to corresponding output reads
('rowtype', dtype([('f0', '<f4', (6,))]))
('dt', dtype('O'))
[ array([([1.0, 1.0, 1.0, 1.0, 1.0, 1.0],),
([1.0, 1.0, 1.0, 1.0, 1.0, 1.0],), ([1.0, 1.0, 1.0, 1.0, 1.0, 1.0],)],
dtype=[('f0', '<f4', (6,))])
array([([1.0, 2.0, 3.0, 2.0, 3.0, 4.0],), ([2.0, 3.0, 4.0, 1.0, 2.0, 3.0],)],
dtype=[('f0', '<f4', (6,))])]
[([1.0, 1.0, 1.0, 1.0, 1.0, 1.0],) ([1.0, 1.0, 1.0, 1.0, 1.0, 1.0],)
([1.0, 1.0, 1.0, 1.0, 1.0, 1.0],)]
[([1.0, 2.0, 3.0, 2.0, 3.0, 4.0],) ([2.0, 3.0, 4.0, 1.0, 2.0, 3.0],)]
Just to get it right: The problem in my original code was a bad definition of my rowtype data structure, right?
Best,
Sven

Using Neural Net weights derived in Matlab on other programming language

I'm having trouble replicating a neural net created in matlab using python. Its a {9,8,4} network. Below is the original output in matlab and python respectively
0.00187283763854096 0.00280257304094145 0.00709416898379967 0.00474275971385824 0.000545071722266366
0.0520122170317888 0.0402746073491970 0.0179208146529717 0.0245726107168336 0.230693355244371
0.430695009441386 0.434492291029203 0.410151021812136 0.416871471927059 0.469873849186641
0.562954025662924 0.539410486293765 0.666336481449288 0.637779009735872 0.284564488176231
[1.0, -1.0, -0.6875955603907775, -0.9999999426232321]
[1.0, -1.0, 0.5569364789701737, -0.9994593106654553]
[1.0, -1.0, 0.5022468075847347, -0.999780120038859]
[1.0, -1.0, 0.4924691499951816, -0.9997110849203137]
[1.0, -1.0, 0.5945295051094253, -0.9991584098381949]
I obtained the input and layered weights using net2.IW{1}, net2.LW{2}. The bias was obtained as follows; net2.b{1} and net2.b{2}.
Without using bias, I got something that looks close:
[-0.6296705512038354, 0.9890465283687858, 0.1368924025968622, 0.5426776395855755]
[-0.05171165478856995, 0.2973298654798701, 0.02897695903082293, 0.0499820714219222]
[-0.10046933055782481, 0.40531232885083035, 0.033067381241777244, 0.06585830703439044]
[0.03167268710874907, 0.5485036035542894, 0.10579223668518502, 0.015475934153332364]
[0.006502829360007152, 0.22928662468119648, 0.03788967208701787, 0.012868192806301859]
Hence I think the problem may lie in the bias; I'm not quite sure though.
Python implementation with weights taken from Matlab
def sigmoid(x):
return math.tanh(x)
def NN(inputs, bias1, bias2):
wsum=[sum([(x*y) for x,y in zip(inputs[0],row)])for row in inputweights]
wsbias=[(x + y) for x,y in zip(wsum,bias1)]
inputactivation=[sigmoid(k) for k in wsbias]
wsoutput=[sum([(x*y) for x,y in zip(inputactivtion,row)])for row in hiddenweights]
wsbias2=[(x + y) for x,y in zip(wsoutput,bias2)]
outputactivation=[sigmoid(k) for k in wsbias2]
return 'output' outputactivation
I would really appreciate any solution that works.
Below are input and Layered weights as well as input and layered bias obtained.
IW=[[-9.1964, -2.3015, 0.2493, 3.3648, -2.6015, -0.0795, -11.2356, 4.6861,-0.8360],
[6.0201, -1.8708, 2.7844, 0.2419, -1.1808, -8.6800, 5.8519, -5.2958, 5.3233],
[0.8597, 0.8644, -0.6913, -0.0397, 0.0619, 0.4506, 1.0687, 0.4090, -0.2874],
[2.9459, 3.2596, 2.2859, 1.1933, 2.9675, -9.6017, 3.5893, 1.4808, -7.5311],
[-0.1533, -1.4806, -2.3748, 0.8059, -0.5502, -1.0447, -0.5920, -1.1667, -1.1447],
[4.7185, -9.2097, 1.1001, -0.0173, 1.4929, 0.3884, 3.7674, 6.3459, -4.2845],
[-16.4031, 8.1351, 2.0689, 2.1267, 6.2093, -8.3875, -15.8493, -0.6096, 2.9214],
[1.7329, 0.1797, 0.1500, 9.1616, -1.7226, 0.9479, 3.2542, -24.4003, -4.2790]]
LW=[[-18.5985, 12.2366, -0.8833, -1.6382, 4.6281, 8.1221, -23.7587, -0.8589],
[12.0462, -11.5464, 6.9612, -10.8562, -7.0647, 5.6653, 16.2527, -7.6119],
[12.4176, 0.9808, 0.7650, -2.9434, -0.2765, -3.0689, -3.1528, 3.0389],
[5.7570, 7.7584, -6.9550, -2.3679, -1.4884, -11.0668, 2.6764, 26.5427]]
bias1=[-1.7639, -1.2599, -0.7560, 0.2520,-0.2520,0.7560, -1.2599, -1.7639]
bias2= [0.2129,-8.1812, 0.0202,4.4512]
My inputs
[[0.0, 0.0, 0.0414444125526, 0.0, 0.0, 0.00670501464516, 0.0, 0.0, 0.0313140652051], [0.0, 0.0, 0.0, 1.0]]
[[0.0, 0.0, 0.00398243636152, 0.0, 0.0, 0.000863557858377, 0.0, 0.0, 0.00356406423776], [0.0, 0.0, 0.0, 1.0]]
[[0.0, 0.0, 0.00440892765754, 0.0, 0.0, 0.000725737283104, 0.0, 0.0, 0.00543503005753], [0.0, 0.0, 0.0, 1.0]]
[[0.0, 0.0, 0.00565322288091, 0.0, 0.0, 0.00236630383341, 0.0, 0.0, 0.00642911490856], [0.0, 0.0, 0.0, 1.0]]
[[0.0, 0.0, 0.00250332223564, 0.0, 0.0, 0.000926998841251, 0.0, 0.0, 0.00241792804103], [0.0, 0.0, 0.0, 1.0]]
Thanks for your suggestions.

how to determine the source of this error message: mc(): not 'converged' in 100 iterations

The code below is a mixture of R and Python, which is used for determining the Outliers values from a list of values.
When I run this code :
#!/usr/bin/python
from rpy import *
r.library("robustbase")
listInput = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0016999999999999999, 0.0025999999999999999, 0.0086, 0.0095999999999999992, 0.012, 0.0132, 0.0149, 0.021700000000000001, 0.022700000000000001, 0.023300000000000001, 0.024799999999999999, 0.0263, 0.029100000000000001, 0.033000000000000002, 0.0424, 0.057099999999999998, 0.0625, 0.063299999999999995, 0.0654, 0.069900000000000004, 0.070599999999999996, 0.072999999999999995, 0.078, 0.085599999999999996, 0.085599999999999996, 0.086499999999999994, 0.088200000000000001, 0.088999999999999996, 0.091300000000000006, 0.092700000000000005, 0.092999999999999999, 0.097199999999999995, 0.099900000000000003, 0.1077, 0.1143, 0.1255, 0.128, 0.13009999999999999, 0.13159999999999999, 0.13270000000000001, 0.1333, 0.1351, 0.14369999999999999, 0.15060000000000001, 0.1547, 0.15529999999999999, 0.15740000000000001, 0.15870000000000001, 0.17630000000000001, 0.1799, 0.18179999999999999, 0.20660000000000001, 0.20930000000000001, 0.2152, 0.219, 0.22919999999999999, 0.22989999999999999, 0.23200000000000001, 0.23369999999999999, 0.23619999999999999, 0.2399, 0.2422, 0.24890000000000001, 0.2545, 0.255, 0.25519999999999998, 0.25990000000000002, 0.26050000000000001, 0.26400000000000001, 0.27489999999999998, 0.27739999999999998, 0.27800000000000002, 0.27889999999999998, 0.28310000000000002, 0.29220000000000002, 0.29470000000000002, 0.30120000000000002, 0.31119999999999998, 0.32829999999999998, 0.32890000000000003, 0.33119999999999999, 0.3347, 0.3407, 0.35310000000000002, 0.35580000000000001, 0.35980000000000001, 0.3705, 0.38009999999999999, 0.38569999999999999, 0.39389999999999997, 0.40060000000000001, 0.4108, 0.4173, 0.42859999999999998, 0.4289, 0.4294, 0.443, 0.44359999999999999, 0.4541, 0.47020000000000001, 0.49109999999999998, 0.5, 0.50449999999999995, 0.50749999999999995, 0.53769999999999996, 0.54779999999999995, 0.58220000000000005, 0.59089999999999998, 0.60070000000000001, 0.60360000000000003, 0.60970000000000002, 0.63070000000000004, 0.63390000000000002, 0.65880000000000005, 0.6653, 0.66620000000000001, 0.66669999999999996, 0.69120000000000004, 0.72240000000000004, 0.7399, 0.74629999999999996, 0.748, 0.76139999999999997, 0.76319999999999999, 0.76719999999999999, 0.79549999999999998, 0.80679999999999996, 0.8085, 0.81599999999999995, 0.82499999999999996, 0.84940000000000004, 0.85919999999999996, 0.8851, 0.8921, 0.89900000000000002, 0.92200000000000004, 0.92379999999999995, 0.95099999999999996, 0.96150000000000002, 0.96319999999999995, 0.96709999999999996, 0.9698, 0.97499999999999998, 0.97589999999999999, 0.98419999999999996, 0.99029999999999996, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
print len(listInput)
TupleInput = tuple(listInput)
print r("adjboxStats")(r.c(TupleInput), coef = 2.5, a = -4, b = 3, do_conf = True, do_out = True)
I get this error:
maximal number of iterations (100 =? 100) reached prematurely
Traceback (most recent call last):
File "/home/kritani/r_python/stack.py", line 49, in <module>
print r("adjboxStats")(r.c(TupleInput), coef = 2.5, a = -4, b = 3, do_conf = True, do_out = True)
rpy.RPy_RException: Error in mc.default(x, na.rm = TRUE) :
mc(): not 'converged' in 100 iterations
When I minimize the number to less than 100 number it works.
I uninstalled R and reinstalled it but it didn't fix the issue. I looked here and here and here and here and there's not a clear solution that really helps.
Does anyone know why this is happening?
Thank you, guys!

Categories

Resources