Unexpected error using Jump with Julia - julia

I am trying to solve an optimization problem, I am getting error as
"ERROR: Expected m to be a JuMP model, but it has type Int64
in validmodel(::Int64, ::Symbol) at C:\Users\Ting.julia\v0.5\JuMP\src\macros.jl:247
in macro expansion; at C:\Users\Ting.julia\v0.5\JuMP\src\macros.jl:252 [inlined]
in macro expansion; at .\REPL[608]:3 [inlined]
in anonymous at .\:?"
Please see the following code(error in constraint 2). Please don't mind the way I have defined arrays, any help is appreciated. Thank you
using JuMP
using Gurobi
m = Model(solver = GurobiSolver()) #if GurobiSolver is to be used .
## insert all matrixs here
#this is the cost for plant to warehouse
plant=4 #last index for {1,2,3}
product=5 #ast index for {2,3,4}
customer=50
warehouse=4
#variable(m, x[i=1:product ,k=1:plant,l=1:warehouse]>=0) #plant to warehouse
#variable(m, y[i=1:product ,k=1:warehouse,l=1:customer]>=0) #warehouse to customer
#variable(m, z[i=1:product ,k=1:plant,l=1:customer ]>=0) #plant to customer
#variable(m, p[i=1:product ,k=1:plant]>=0) #any product i produced at plant k
#THIS GIVES COST OF PRODUCING AT ANY PRODUCT I AT PLANT K
PC=[500 500 500 500;
400 400 400 400;
300 300 300 300;
200 200 200 200;
100 100 100 100]
#DEMAND OF I AT ANY COSTOMER M, SHOULD BE A MATRIX OF (5*50)
D=[4650.28 10882.70 7920.68 2099.06 4920.32 5077.80 2259.10 9289.30 9782.28 4671.85 6625.68 6956.80 5288.12 4144.78 11121.56 9152.47 10206.88 4601.63 2718.91 1439.39 2984.38 3631.17 3934.48 12314.28 4188.04 8437.43 6302.34 1248.62 6286.56 7333.46 11027.86 6233.33 7240.82 5652.13 10276.03 1197.22 11160.13 4510.31 8850.49 8291.09 1081.47 7652.23 3936.85 2640.47 7726.72 1422.96 1644.78 1060.39 6858.66 6554.45;
528.11 4183.80 352.45 366.34 1961.78 3419.11 337.44 708.15 3556.56 1649.95 583.25 1525.97 1569.92 349.93 1904.59 2221.80 2139.63 1822.87 546.11 784.93 948.33 1424.26 1910.64 2275.11 1527.57 2477.49 1592.14 90.86 2635.48 131.02 2402.35 2669.67 105.34 1350.60 4233.60 411.54 687.88 89.09 213.23 2817.29 8.08 1586.51 577.07 1529.34 2919.06 393.97 85.45 214.93 3193.94 1565.64;
480.26 622.67 131.04 14.45 1299.71 599.27 83.08 197.37 1986.77 409.08 371.12 1249.92 216.21 62.43 34.96 1752.75 227.06 184.26 219.92 577.37 138.71 36.23 1659.02 1323.50 236.64 2557.64 76.74 74.08 363.64 52.96 456.67 1589.86 81.89 617.11 509.86 145.52 14.13 83.22 215.03 2749.34 7.12 490.00 120.42 456.03 430.22 165.02 66.16 150.70 2806.58 1403.70;
307.36 474.39 7.56 11.76 882.03 222.62 27.29 158.13 55.94 332.98 171.36 492.81 44.12 24.08 15.57 739.97 11.09 199.51 136.46 194.40 63.72 2.42 355.99 1005.42 66.33 1647.51 47.22 21.32 218.06 11.54 305.81 387.71 8.50 248.38 9.20 76.05 13.12 39.83 146.52 379.44 2.75 239.53 94.06 136.96 290.16 237.75 9.04 110.64 842.58 395.08;
76.52 280.62 5.06 6.75 281.41 215.58 5.78 54.69 20.79 22.08 78.50 322.13 34.13 6.37 11.66 178.33 3.40 142.11 60.70 46.17 6.96 1.15 227.70 669.39 3.21 526.85 45.91 17.00 131.43 11.19 189.00 43.93 3.36 110.66 1.75 41.34 0 38.63 50.78 241.19 0 176.32 94.25 99.59 153.50 123.02 3.76 122.52 853.48 99.62]
a = Array{Float64}(5,4,4)
a[1,1,1]=a[2,1,1]=a[3,1,1]=a[4,1,1]=a[5,1,1]=0.2*528.42
a[1,2,1]=a[2,2,1]=a[3,2,1]=a[4,2,1]=a[5,2,1]=0.2*1366.16
a[1,3,1]=a[2,3,1]=a[3,3,1]=a[4,3,1]=a[5,3,1]=0.2*1525.41
a[1,4,1]=a[2,4,1]=a[3,4,1]=a[4,4,1]=a[5,4,1]=0.2*878.11
a[1,1,2]=a[2,1,2]=a[3,1,2]=a[4,1,2]=a[5,1,2]=0.2*1692.25
a[1,2,2]=a[2,2,2]=a[3,2,2]=a[4,2,2]=a[5,2,2]=0.2*1553.06
a[1,3,2]=a[2,3,2]=a[3,3,2]=a[4,3,2]=a[5,3,2]=0.2*817.18
a[1,4,2]=a[2,4,2]=a[3,4,2]=a[4,4,2]=a[5,4,2]=0.2*2164.69
a[1,1,3]=a[2,1,3]=a[3,1,3]=a[4,1,3]=a[5,1,3]=0.2*2006.5
a[1,2,3]=a[2,2,3]=a[3,2,3]=a[4,2,3]=a[5,2,3]=0.2*1385.04
a[1,3,3]=a[2,3,3]=a[3,3,3]=a[4,3,3]=a[5,3,3]=0.2*998.58
a[1,4,3]=a[2,4,3]=a[3,4,3]=a[4,4,3]=a[5,4,3]=0.2*2148.45
a[1,1,4]=a[2,1,4]=a[3,1,4]=a[4,1,4]=a[5,1,4]=0.2*1073.07
a[1,2,4]=a[2,2,4]=a[3,2,4]=a[4,2,4]=a[5,2,4]=0.2*368.35
a[1,3,4]=a[2,3,4]=a[3,3,4]=a[4,3,4]=a[5,3,4]=0.2*450.12
a[1,4,4]=a[2,4,4]=a[3,4,4]=a[4,4,4]=a[5,4,4]=0.2*1129.27
#objective(m, Min ,sum(a[i,k,l]* x[i,k,l] for i=1:product for k=1:plant for l=1:warehouse) + sum(c_dash[i,l,m]* y[i,l,m] for i=1:product for l=1:warehouse for m=1:plant) +sum(c_dash_dash[i,k,m]* z[i,k,m] for i=1:product for k=1:plant for m=1:customer)+sum(PC[i,k]* p[i,k] for i=1:product for k=1:plant)) #to be changes
#constraint(m,p[1,2]==0)
#constraint(m,p[1,3]==0)
#constraint(m,p[1,4]==0)
#constraint(m,p[2,1]==0)
#constraint(m,p[2,3]==0)
#constraint(m,p[2,4]==0)
#constraint(m,p[3,1]==0)
#constraint(m,p[3,2]==0)
#constraint(m,p[3,4]==0)
#constraint(m,p[4,1]==0)
#constraint(m,p[4,2]==0)
#constraint(m,p[4,3]==0)
#constraint(m,p[5,1]==0)
#constraint(m,p[5,2]==0)
#constraint(m,p[5,3]==0)
#constraint(m,p[1,1]<=450000)
#constraint(m,p[2,2]<=108000)
#constraint(m,p[3,3]<=45000)
#constraint(m,p[4,4]<=18000)
#constraint(m,p[5,4]<=9000)
#constraint 1
#constraint(m,415728.69-0.8* sum(y[i,l,m] for i=1:product for l=1:warehouse for m=1:customer) <=0)
#constrainst 2
for m=1:customer
for i=1:product
#constraint(m, D[i,m]-sum(z[i,k,m] for k=1:plant)-sum(y[i,l,m] for l=1:warehouse) <=0 ) #cant get
end
end

#constrainst 2
for m=1:customer
for i=1:product
#constraint(m, D[i,m]-sum(z[i,k,m] for k=1:plant)-sum(y[i,l,m] for l=1:warehouse) <=0 ) #cant get
end
end
The error explains the problem very well. Your outer-loop variable here is m, which makes usage of m inside the loop refers to the loop variable and not to your model. m is also used to hold the model in the outer-scope. Change your loop variable or model variable to something else and the problem is fixed.

Related

How to plot an antenna pattern in a polar diagram in Octave?

I'm having some problems with polar plot in Octave. In particular I made a script that combine the horizontal and vertical antenna pattern in order to obtain the 3D antenna pattern of the antenna such that the result is a matrix of 360x360 elements. If I plot the matrix by means of surf function I obtain that image but I would like to get an antenna pattern diagram. How I can do that?
EDIT:
theta3D = linspace(0, 2*pi - (2*pi/360), 360);
phi3D = linspace(0, 2*pi - (2*pi/360), 360);
%% from dBm to dB
maxGainVdB = mGVNnA - 30;
maxGainHdB = mGHNnA - 30;
%% from dB to Watt
maxGainVWatt = 10.^(maxGainVdB/10);
maxGainHWatt = 10.^(maxGainHdB/10);
%% normalization
maxGainVWattNorm = maxGainVWatt./max(maxGainVWatt);
maxGainHWattNorm = maxGainHWatt./max(maxGainHWatt);
%% Gv and Gh
Gv = 10*log10(maxGainVWattNorm);
Gh = 10*log10(maxGainHWattNorm);
%% weighting factors
% where "i" is theta and j is phi
for i = 1 : length(phi3D)
for j = 1 : length(theta3D)
w1(i, j) = maxGainVWattNorm(i)*(1 - maxGainHWattNorm(j));
w2(i, j) = maxGainVWattNorm(j)*(1 - maxGainHWattNorm(i));
end
end
%% normalization-related parameter
k = 2; %% As indicated in Chapter 2
%% estimated G
for i = 1 : length(phi3D)
for j = 1 : length(theta3D)
estG(i, j) = ((Gh(i)*w1(i,j) + Gv(j)*w2(i,j))/((w1(i,j)^k + w2(i,j)^k))^(1/k));
end
end
figure
[X, Y] = meshgrid (theta3D, phi3D);
surf(X,Y,estG)
DATA
mGHNnA = [0.0762 0.0976 0.1207 0.146 0.1744 0.2066 0.2428 0.2827 0.3256 0.3705 0.4165 0.4631 0.5107 0.5602 0.6129 0.6704 0.7334 0.8021 0.8754 0.9518 1.0294 1.1067 1.1834 1.2608 1.3419 1.4318 1.5376 1.6653 1.8213 2.011 2.2382 2.5046 2.8096 3.1494 3.5171 3.8976 4.2687 4.6021 4.8717 5.0727 5.201 5.2687 5.2965 5.3066 5.3189 5.3365 5.3865 5.4558 5.5635 5.7028 5.8633 6.0489 6.2538 6.4708 6.6929 6.914 7.1293 7.3344 7.5209 7.6879 7.8455 7.9974 8.1362 8.2677 8.4072 8.547 8.6955 8.8539 9.025 9.21 9.4099 9.6251 9.8558 10.102 10.362 10.636 10.924 11.224 11.536 11.858 12.189 12.528 12.875 13.229 13.59 13.954 14.323 14.696 15.071 15.447 16.203 16.58 17.089 17.593 18.093 18.588 19.077 19.56 20.036 20.506 20.969 21.424 21.861 22.278 22.683 23.081 23.47 23.856 24.235 24.609 24.98 25.344 25.698 26.037 26.347 26.622 26.87 27.09 27.289 27.459 27.601 27.729 27.849 27.962 28.068 28.158 28.244 28.282 28.272 28.233 28.204 28.181 28.182 28.2 28.21 28.203 28.206 28.181 28.185 28.238 28.346 28.526 28.794 29.158 29.616 30.155 30.753 31.375 31.988 32.556 33.032 33.32 33.435 33.452 33.476 33.597 33.831 34.167 34.581 35.047 35.48 35.784 36.026 36.134 35.959 35.742 35.544 35.466 35.575 35.746 35.995 36.162 36.19 36.11 35.912 35.695 35.529 35.417 35.401 35.464 35.467 35.622 35.747 35.773 35.787 35.827 35.802 35.722 35.596 35.544 35.59 35.687 35.784 35.857 35.867 35.804 35.679 35.462 35.131 34.68 34.179 33.68 33.231 32.833 32.532 32.326 32.18 32.035 31.752 31.265 30.628 29.95 29.221 28.526 27.919 27.419 27.03 26.737 26.542 26.415 26.341 26.301 26.269 26.241 26.212 26.179 26.143 26.102 26.051 25.983 25.892 25.795 25.707 25.636 25.584 25.542 25.502 25.464 25.424 25.362 25.269 25.156 25.013 24.827 24.604 24.343 24.042 23.713 23.361 22.998 22.62 22.229 21.827 21.418 21.004 20.587 20.156 19.72 19.278 18.833 18.385 17.934 17.478 17.018 16.555 16.086 15.614 15.138 14.658 14.175 13.689 13.336 12.982 12.629 12.277 11.926 11.577 11.23 10.887 10.549 10.215 9.8873 9.5665 9.2535 8.9474 8.6508 8.3601 8.0783 7.8076 7.5485 7.2995 7.0654 6.8356 6.6223 6.418 6.2237 6.0401 5.8621 5.6946 5.5356 5.384 5.2382 5.0961 4.9558 4.8113 4.6579 4.5018 4.3427 4.182 4.022 3.8609 3.7051 3.5585 3.4213 3.2873 3.1583 3.032 2.9015 2.7555 2.6037 2.4462 2.284 2.1188 1.9533 1.7903 1.6325 1.4827 1.3435 1.209 1.0844 0.9762 0.8832 0.7952 0.7224 0.6616 0.609 0.5607 0.5128 0.4625 0.4103 0.3567 0.3033 0.2521 0.2051 0.164 0.1295 0.1013 0.0786 0.06 0.0442 0.0304 0.0182 0.0083 0.0019 0 0.0035 0.0125 0.0242 0.0388 0.0564]
and
mGVNnA = [ 1.7 1.1099 0.7069 0.4755 0.2901 0.1465 0.0475 0 0.0014 0.0449 0.1292 0.2868 0.4673 0.7364 1.2223 1.9732 3.0173 4.3603 5.9631 7.7179 9.5019 9.832 8.9113 8.2694 8.0057 8.1343 8.6399 9.5171 10.742 12.285 14.065 16.092 18.473 21.416 25.15 27.353 27.395 26.174 23.967 21.86 20.131 18.734 17.599 16.638 15.887 15.369 15.082 15.024 15.211 15.606 16.196 16.958 17.868 18.867 20 20.151 19.842 19.695 19.725 19.787 19.905 20.082 20.265 20.432 20.595 20.789 21.013 21.281 21.623 22.058 22.536 23.101 23.715 24.38 25.113 25.898 26.737 27.595 28.478 29.381 30.284 31.155 31.971 32.721 33.389 33.969 34.473 34.88 35.237 35.563 35.885 36.251 36.805 37.442 38.143 38.785 39.282 39.452 39.252 38.808 38.293 37.764 37.253 36.773 36.34 35.953 35.634 35.368 35.192 35.093 35.087 35.161 35.305 35.638 35.968 36.19 36.22 36.098 35.797 35.382 35.001 34.788 34.768 34.921 35.411 36.172 36.807 36.485 36.261 35.984 35.618 35.165 34.735 34.498 34.647 35.242 36.268 37.584 38.828 39.695 40.087 40.283 40.635 41.382 42.64 43.356 41.606 40.07 39.359 39.185 39.081 38.836 38.624 38.456 38.255 38.206 38.493 39.266 40.491 41.983 43.328 42.563 40.545 38.503 37.071 36.429 36.194 36.104 35.836 35.579 35.481 35.506 35.707 35.994 36.07 36.031 36.033 36.214 36.667 37.435 38.147 38.873 39.727 40.902 42.706 43.934 43.635 43.926 44.379 44.797 45.114 45.558 46.371 47.239 49.24 52.957 57.002 55.602 53.712 53.855 57.666 52.999 48.404 45.794 44.523 44.54 44.979 45.826 47.281 48.725 49.537 49.035 47.911 45.782 43.136 40.9 39.415 38.682 38.471 38.664 39.083 39.55 39.89 39.954 39.921 40.111 40.907 41.583 41.361 41.264 40.952 40.156 39.005 37.776 36.579 35.531 34.625 33.843 33.158 32.54 32.059 31.661 31.352 31.117 30.908 30.74 30.578 30.447 30.306 30.141 29.997 29.704 29.318 28.964 28.61 28.262 27.903 27.512 27.083 26.622 26.123 25.592 25.037 24.464 23.88 23.292 22.702 22.114 21.537 20.976 20.433 19.985 19.564 19.172 18.811 18.484 18.191 17.938 17.728 17.566 17.458 17.411 17.431 17.437 16.937 16.486 16.093 15.757 15.479 15.269 15.133 15.062 15.072 15.144 15.254 15.407 15.568 15.726 15.86 15.971 16.077 16.2 16.408 16.719 17.174 17.79 18.611 19.673 21.051 22.834 24.971 27.442 29.851 27.032 24.994 23.406 21.624 20.012 18.602 17.435 16.433 15.668 15.115 14.729 14.47 14.339 14.383 14.654 15.252 16.216 14.91 13.992 13.353 12.978 12.89 13.16 13.841 14.942 16.463 18.341 20.559 23.437 26.905 27.021 23.385 19.308 16.1 13.668 11.801 10.36 9.2831 8.5509 8.1662 8.1298 8.4381 7.8963 6.1559 4.6964 3.4785 2.4834 ]
I have no idea which kind of polar plots you are expecting, but the below code may help you to make it as an example.
2D polar plot
% polar plot for G vs. phi, when theta = pi
polar(phi3D, estG(:,length(theta3D)/2+1));
hold on;
% polar plot for G vs. theta, when phi = pi
polar(theta3D, estG(length(phi3D)/2+1,:));
legend("G vs. phi #(theta=pi)","G vs. theta #(phi=pi)");
title("2D radiation pattern");
hold off;
- 3D polar plot
[X, Y] = meshgrid (theta3D, phi3D);
surf(X,Y,estG,'LineStyle','none');
xlabel("theta");
ylabel("phi");
zlabel("G");
colormap("jet");
colorbar
The code that you have included does generate an estimate of gain vs theta and phi, however, you are plotting it on rectangular coordinates. if you noticed, in the resultant figure, the x and y axes are ranging from 0 to 2pi.
you created a (theta, phi, magnitude) data set, and need to convert that to an x,y,z data set.
doing a coordinate transformation, similar to:
xconv = estG.*sin(theta3D).*cos(phi3D);
yconv = estG.*sin(theta3D).*sin(phi3D);
zconv = estG.*cos(theta3D);
may give you what you need.
surf(xconv,yconv,zconv,'Edgecolor','none')
produces:
Since I'm not exactly sure what output would be correct from this data, I can't tell if that quite has it. There may be some ordering issues with mesh and surf plot data that i'm not aware of.
I recommend always starting simple. Work with a unit gain omnidirectional antenna, and see if your process above can go from two circle plots to a sphere. then generate more complex patterns.
for reference, here's a decent set of classroom exercises on 3D parametric plots

Plotting a 1D dot plot in SAS

Hello, I would like to plot something that is close to this but
I cannot seem to get it.
I have the data
data table2_1;
input Modified_Mortar Unmodifided_Mortar;
cards;
16.85 16.62
16.40 16.75
17.21 17.37
16.35 17.12
16.52 16.98
17.04 16.87
16.96 17.34
17.15 17.02
16.59 17.08
16.57 17.27
;
run;
And I tried
proc freq data=table2_1;
tables Modified_Mortar / plots=freqplot (type=dotplot);
tables Unmodifided_Mortar / plots=freqplot (type=dotplot);
run;
but it gave me an unnecessarily huge plot which was spaced equally and cannot compare the two distributions as I intended.
I played around a bit with sgplot and this is the closest I could come up with. It's not exact, but with a little fiddling in an image editor you can pretty much get it.
data table2_1;
input Modified_Mortar Unmodifided_Mortar;
retain mod_line 0.75 unmod_line 0;
cards;
16.85 16.62
16.40 16.75
17.21 17.37
16.35 17.12
16.52 16.98
17.04 16.87
16.96 17.34
17.15 17.02
16.59 17.08
16.57 17.27
;
run;
proc sgplot data=table2_1;
label Modified_Mortar = 'Strength (kgf/cm squared)';
scatter x = Modified_Mortar y=mod_line / markerattrs=(symbol=circlefilled color=black size=10);
scatter x = Unmodifided_Mortar y=unmod_line / markerattrs=(symbol=circlefilled color=bib size=10);
refline -0.25 / axis=y lineattrs=(color=bib thickness=2) name='mod' legendlabel='Unmodified' ;
refline 0.5 / axis=y lineattrs=(color=black thickness=2) name='unmod' legendlabel='Modified';
yaxis display=(nolabel) min=-0.25 max=15;
xaxis values=(16.24 to 17.50 by 0.14) min=16.30 max=17.40 valueattrs=(size=12) labelattrs=(size=12);
keylegend 'mod' 'unmod' / location=outside position=bottom valueattrs=(size=12);
run;
Here is a different approach that uses the data in a treatment:response categorical form. A labeled triangle marker is used to show the mean (triangle apex being the balance point)
data have;
treatment = 'Modified '; y=1.13; input response #; output;
treatment = 'Unmodified'; y=0.13; input response; output;
attrib
response label = "Strength (kgf/cm2)"
;
cards;
16.85 16.62
16.40 16.75
17.21 17.37
16.35 17.12
16.52 16.98
17.04 16.87
16.96 17.34
17.15 17.02
16.59 17.08
16.57 17.27
;
run;
proc sql;
create table plot as
select * from have
outer union corresponding
select
treatment,
case treatment
when ('Unmodified') then -0.15
when ('Modified ') then 0.85
else 0
end as y2,
mean(response) as mean format=5.2
from have
group by treatment;
quit;
ods proclabel "Concrete dot plot";
ods graphics / height=220px width=800px;
proc sgplot data=plot description="Response to treatment";
title "Concrete strength response to treatment";
scatter
x=response y=y
/ markerattrs=(symbol=circlefilled color=black size=12px)
;
scatter
x=mean y=y2
/ datalabel=mean
datalabelpos=bottom
markerattrs=(symbol=triangle color=black size=12px)
;
keylegend
/ exclude = ("y" "y2")
;
yaxis
offsetmin = 0.2
values = ( 0 1 2 )
valuesdisplay = ( "Unmodified" "Modified" " " )
display = ( noticks nolabel )
colorbands = odd
;
xaxis
grid
;
refline 0.00 ;
refline 1.00 ;
run;
title;
footnote;

R - Setting the class of an object created with by()

First a little bit of context:
In my package summarytools, I've defined a print method for objects of classs "summarytools". I have also created a function view() that handles objects created using by() or lapply() in such a way that the output doesn't include the lines stating the group -- or the variable in the case of lapply(); summarytools displays its own headings containing that information, so there is some redundancy when using print. Also, the main headings are not repeated when using view().
Here's an example. Note that in this version (in development), I included a message advising the use of view():
> library(summarytools)
> (tmp <- with(tobacco, by(smoker, gender, freq)))
gender: F
For best results printing list objects with summarytools, use view(x, method = 'pander')
Frequencies
tobacco$smoker
Type: Factor
Group: gender = M
Freq % Valid % Valid Cum. % Total % Total Cum.
----------- ------ --------- -------------- --------- --------------
Yes 147 30.06 30.06 30.06 30.06
No 342 69.94 100.00 69.94 100.00
<NA> 0 0.00 100.00
Total 489 100.00 100.00 100.00 100.00
------------------------------------------------------------------
gender: M
Frequencies
tobacco$smoker
Type: Factor
Group: gender = F
Freq % Valid % Valid Cum. % Total % Total Cum.
----------- ------ --------- -------------- --------- --------------
Yes 143 29.24 29.24 29.24 29.24
No 346 70.76 100.00 70.76 100.00
<NA> 0 0.00 100.00
Total 489 100.00 100.00 100.00 100.00
And now using view():
> view(tmp, method = "pander")
Frequencies
tobacco$smoker
Type: Factor
Group: gender = M
Freq % Valid % Valid Cum. % Total % Total Cum.
----------- ------ --------- -------------- --------- --------------
Yes 147 30.06 30.06 30.06 30.06
No 342 69.94 100.00 69.94 100.00
<NA> 0 0.00 100.00
Total 489 100.00 100.00 100.00 100.00
Group: gender = F
Freq % Valid % Valid Cum. % Total % Total Cum.
----------- ------ --------- -------------- --------- --------------
Yes 143 29.24 29.24 29.24 29.24
No 346 70.76 100.00 70.76 100.00
<NA> 0 0.00 100.00
Total 489 100.00 100.00 100.00 100.00
I've thought about ways through which the objects of class "by" would automatically be dispatched to view() instead of print(). If I add the class "summarytools" to those objects, the print() method could redirect the call to view(), making it simpler for users to get proper, optimal outputs.
The solutions I've thought of, so far, are the following:
Adding a "by" argument to the functions so that I have full control on the created objects' proporties. I'm not fond of this solution, since 1) I try to rely on base R functions that people are familiar with rather than introducing new parameters, and 2) I'd still have a similar issue when objects are created with lapply().
Redefining by() so that when it's called from one of summarytools' functions, it appends the desired class to the created objects. I've avoided this because I'm hesitant to redefine base functions. I'd rather not see messages to the effect that objects have been masked when the package is loaded.
Defining a package-specific by(), such as by_st(); I could use basically the same code as by.default() and by.data.frame(), the only difference being that I'd add the "summarytools" class to the created objects. This is a sort of compromise that I'm considering.
My question is the following: could there be other, maybe better solutions I'm not seeing?
You could use S3 method for print.by to dispatch to your custom function:
old.print.by = print.by # save the original function so we can restore it later
print.by = summarytools::view # redefine print.by to dispatch to custom function
tmp
To restore original function later you can do print.by = old.print.by.
If you only want your new function to operate on lists that contain objects of class "summarytools", you can use
print.by = function(x, method = 'pander', ...) {
if ("summarytools" %in% class(x[[1]])) {
summarytools::view(x, method, ...)
} else {
old.print.by(x, ...)
}
}

How can i make a python file run another which is not in same directory?

This is my code...I have tried many solutions given on stackoverflow but i am not able to run another python file which is not in same directory
f.py
import os
print "Start..."
file='"C:\Users\Mohit\Desktop\ML PROJECT\Practical Session on R\Practical
Session on R\Session II - Regression\run.py"'
os.system('python file ')
print "Done"
Output:
Fatal error: cannot open file 'file': No such file or directory
run.py
import os
print "Start..."
files=r'"C:\Users\Mohit\Desktop\ML PROJECT\Practical Session on R\Practical
Session on R\Session II - Regression\decisionTree.R"'
os.system('Rscript '+files)
print "Done"
I get the desired result when i run run.py.
Output:
C:\Users\Mohit\Desktop\ML PROJECT\Practical Session on R\Practical Session
on R\
Session II - Regression>python r.py
Start...
START
elapsed
0.17
Step 1: Library Inclusion
Step 2: Variable Declaration[1]
[1] "regressionDataSet.csv"
Step 3: Data Loading RMSD
irNumber
14395 1.167 5364.27 4616.64
15435 2.500 25468.10 475274.00 -
8739 4.039 5921.03 7071.89
11586 0.000 14192.70 75413.00
13765 0.000 17432.40 245147.00 -
10087 3.814 7333.51 26580.70
[1] 16382
[1] "RMSD" "Area"
[5] "SS" "ResidueLeng
Step 4: Counting dataset[1] 1638
Step 5: Choose Target Variable[1
Step 6: Choose Inputs Variable[1
"SS"
[5] "ResidueLength" "PairNumber"
[1] 6
Step 7: Select training dataset
th PairNumber RMSD
14395 5364.27 4616.64 -696.
15435 25468.10 475274.00 -10600.
8739 5921.03 7071.89 -1658.
11586 14192.70 75413.00 -7939.
13765 17432.40 245147.00 -10885.
10087 7333.51 26580.70 -2746.
[1] 8191
Step 8: Select testing dataset
PairNumber RMSD
10216 20510.40 254178.0 44500.0
2385 9981.42 28499.0 -4789.0
1886 21107.10 192443.0 -4860.0
13684 17765.00 76543.0 -8164.0
10319 6308.91 10287.3 -3370.0
13088 5844.34 11139.7 -1879.7
[1] 8192
Step 9: Model Building -> decis
ength + PairNumber
n= 8191
node), split, n, deviance, yval
* denotes terminal node
1) root 8191 23819.88000 2.364
2) Energy< -6161.885 1592 4
4) ResidueLength< 387.5 74
8) Energy< -7785.3 262
9) Energy>=-7785.3 481
5) ResidueLength>=387.5 84
10) Energy< -12910.5 173
11) Energy>=-12910.5 676
22) ResidueLength< 467.
44) ResidueLength>=39
45) ResidueLength< 39
23) ResidueLength>=467.
3) Energy>=-6161.885 6599 17
6) SS< 21.5 1584 3795.813
7) SS>=21.5 5015 13126.850
14) Energy< -3971.125 163
28) ResidueLength< 192.
29) ResidueLength>=192.
58) ResidueLength< 26
116) Energy< -4680.5
117) Energy>=-4680.5
59) ResidueLength>=26
15) Energy>=-3971.125 337
30) Area< 8601.98 1655
60) Energy< -2933.36
61) Energy>=-2933.36
31) Area>=8601.98 1721
Step 10: Prediction using -> de
13684 10319 13088
3.24618361 0.51722167 3.10727318
Step 11: Extracting Actual[1] 3.
Step 12: Model Evaluation[1] 0.5
[1] 0.25
[1] 1.19
[1] 48.19
elapsed
0.53
null device
1
modelName r R rm
elapsed decisionTree 0.5 0.25 1.
Step 13: Writing to file
Step 14: Saving the Model -> dec
Done
Total Time Taken: 0.53 secDone
But i get the following error when i run it through f.py
Error:
Start...
Start...
START
elapsed
0.18
Step 1: Library Inclusion
Step 2: Variable Declaration[1] "decisionTree"
[1] "regressionDataSet.csv"
Step 3: Data LoadingError in file(file, "rt") : cannot open the connec
Calls: read.csv -> read.table -> file
In addition: Warning message:
In file(file, "rt") :
cannot open file 'regressionDataSet.csv': No such file or directory
Put an r in front of your file path, so that the backslashes \ don't escape strings where you don't want them to be escaped (see also this question).
Secondly os.system('python file') will literally execute python file, your variable isn't being used.
Also make sure there's no linebreak your file path (just one long line).
import os
print "Start..."
folder = r'C:\Users\Mohit\Desktop\ML PROJECT\Practical Session on R\Practical Session on R\Session II - Regression'
file= r'"{}\run.py"'.format(folder)
os.chdir(folder)
os.system('python '+file)
print "Done"

Suggestion for curve fitting

I have this set of data:
X: Y:
0. 0.
0.001417162 0.0118
0.002352761 0.0128
0.003123252 0.0135
0.003866221 0.0138
0.004045083 0.0147
0.005544762 0.0151
0.006260197 0.0156
0.007195755 0.0157
0.007883656 0.0158
0.008805432 0.0159
0.009314465 0.0165
0.010566391 0.0168
0.011047891 0.0186
0.011666955 0.0177
0.012341036 0.0225
0.013193938 0.0399
0.013854235 0.087
0.014500764 0.1479
0.015381122 0.198
0.015601208 0.2586
0.01638525 0.3111
0.016976706 0.3693
0.017691939 0.42
0.018338382 0.4737
0.018861027 0.5223
0.01963122 0.5691
0.021625353 0.6183
0.020923988 0.6684
0.021377815 0.711
0.021927895 0.7551
0.022574222 0.7938
0.023633053 0.8382
0.023646804 0.8742
0.024279325 0.912
0.025131822 0.9495
0.0256543 0.9891
0.026094271 1.0215
0.026685464 1.0596
0.027345378 1.098
0.028101497 1.1328
0.028513912 1.1739
0.029077528 1.1997
0.029723601 1.2339
0.030355902 1.2741
0.031056901 1.3041
0.031428005 1.3383
0.032087723 1.3665
0.032692438 1.3983
0.033242157 1.4262
0.033846824 1.4589
0.034410239 1.4877
0.035248448 1.5222
0.035729364 1.5534
0.036430096 1.5861
0.037034618 1.6179
0.037694064 1.6536
0.038408425 1.6842
0.039067798 1.7121
0.039521096 1.7427
0.040207877 1.7763
0.04071607 1.8075
0.041279177 1.8381
0.04129291 1.8711
0.042707418 1.9065
0.043366544 1.9332
0.043860863 1.9659
0.044368889 1.9959
0.045055371 2.0202
0.045700624 2.0487
0.04626347 2.0796
0.047059639 2.1105
0.047540055 2.1339
0.048308673 2.1618
0.048857648 2.1849
0.049557546 2.2203
0.050229948 2.2425
0.052082233 2.2716
0.051355084 2.2983
0.051945039 2.3193
0.052466363 2.3475
0.053371748 2.3718
0.053851839 2.3937
0.054647359 2.4189
0.055072521 2.4372
0.055675941 2.4633
0.056306742 2.4882
0.057060898 2.5131
0.057691594 2.5332
0.058582712 2.5527
0.059007671 2.5755
0.059597094 2.5941
0.060172767 2.6115
0.065187502 2.6403
0.06131028 2.6592
0.061968042 2.6808
0.062598344 2.6991
0.063173791 2.7246
0.063790292 2.7441
0.064393043 2.7633
0.065091624 2.7795
0.065502522 2.8011
0.066433804 2.8212
0.066598135 2.8368
0.067351271 2.8545
0.067981104 2.8665
0.068610879 2.8845
0.069309041 2.9046
0.069870256 2.9214
0.070253498 2.9355
0.070828319 2.9499
0.07159467 2.9691
0.072046228 2.9856
0.072620893 2.9982
0.07326391 3.0108
0.073893183 3.0255
0.074467682 3.0387
0.075165218 3.0531
0.075862676 3.0654
0.076395973 3.0735
0.077230012 3.0879
0.077571798 3.0996
0.077968246 3.1116
0.078720058 3.1251
0.079485442 3.1332
0.080168736 3.1473
0.080797297 3.1524
0.081671703 3.1647
0.082518656 3.1761
0.082737205 3.1794
0.083242565 3.1911
0.083843476 3.207
0.084594523 3.2157
0.083993693 3.2217
0.086028058 3.2313
0.086806105 3.2412
0.087515804 3.2475
0.087979788 3.2562
0.089221428 3.2658
0.089289641 3.2727
0.090053572 3.2823
0.090599168 3.285
0.091485638 3.2988
0.092508299 3.3006
0.092794607 3.309
0.093585278 3.3177
0.094443969 3.3255
0.095029975 3.336
0.095752165 3.3381
0.096378886 3.3468
0.097182604 3.3498
0.097781901 3.3573
0.098585385 3.3612
0.099238967 3.3702
0.102192566 3.372
0.100464189 3.3816
0.101226388 3.3879
0.101961246 3.396
0.102519116 3.4038
0.103335387 3.4113
0.103920292 3.4134
0.104777107 3.4206
0.105416212 3.423
0.105932869 3.4308
0.106952407 3.4353
0.107550426 3.4431
0.108284246 3.4479
0.108759804 3.4539
0.109439081 3.4587
0.110118251 3.4662
0.11096027 3.4701
0.111802122 3.4749
0.112182257 3.4857
0.113132445 3.4902
0.113878868 3.4929
0.114530181 3.5028
0.11465229 3.5076
0.116063069 3.513
0.116619106 3.5181
0.117378448 3.5247
0.118246089 3.5295
0.118869589 3.5286
0.119479439 3.5364
0.120292424 3.5451
0.120807227 3.5511
0.121728283 3.5565
0.122283519 3.5625
0.123068837 3.5622
0.123745705 3.5691
0.124544254 3.5775
0.125247919 3.5796
0.125924395 3.5868
0.126614273 3.5892
0.128683133 3.5958
0.127993643 3.5991
0.128602023 3.6057
0.129507645 3.6093
0.130115772 3.6132
0.130669753 3.6156
0.131682911 3.6222
0.132263658 3.6234
0.132911821 3.6288
0.133870342 3.6291
0.136717348 3.6336
0.13504451 3.6396
0.135692157 3.6372
0.13621828 3.6432
0.137068001 3.6465
0.141030546 3.6522
0.138470251 3.6501
0.139009423 3.6567
0.140181824 3.6615
0.140532116 3.6633
0.141124835 3.6588
0.141717448 3.6675
0.14257924 3.6711
0.143319661 3.6741
0.143844585 3.6729
0.144813453 3.6753
0.145243967 3.678
0.1472209 3.6849
0.14672342 3.6879
0.147301565 3.6888
0.147866163 3.6933
0.148403782 3.6927
0.149277216 3.6972
0.149962355 3.7011
0.151922897 3.7077
0.151426165 3.7023
0.152070559 3.7089
0.153251595 3.7107
0.153587034 3.7134
0.15429804 3.7191
0.154861361 3.7191
0.155706144 3.7221
0.157086785 3.7206
0.157086785 3.7272
0.156925966 3.7269
0.158480178 3.7335
0.15912306 3.7272
0.159618519 3.7356
0.160381629 3.7359
0.161171304 3.7386
0.161853731 3.7377
0.162415608 3.7398
0.163151233 3.7437
0.163993625 3.7443
0.165062969 3.7533
0.165330242 3.7509
0.166065112 3.7512
0.166866568 3.7569
0.167494215 3.7635
0.168108371 3.7569
0.168829162 3.7638
0.169536423 3.7626
0.173429745 3.7581
0.171070418 3.7617
0.171803762 3.7653
0.172790131 3.7635
0.172936723 3.7644
0.174029244 3.7695
0.174761783 3.7701
0.175334355 3.7668
0.176173017 3.7704
0.176705362 3.7722
0.177490375 3.7701
0.178261854 3.774
0.178979922 3.7797
0.178793775 3.78
0.180774223 3.7887
0.182394664 3.8301
0.18451827 3.8169
0.186282158 3.8067
0.186772642 3.7731
0.188058046 3.7782
0.188587916 3.7734
0.189395747 3.7749
0.189885613 3.7707
0.190560674 3.7734
0.191447234 3.7752
0.192280569 3.7713
0.193007849 3.7704
0.193946376 3.7701
0.194329613 3.7734
0.195188367 3.7647
0.195716677 3.7644
0.196416507 3.7683
0.197142527 3.7695
0.197709986 3.7596
0.198923623 3.7662
0.199714786 3.7617
0.200189355 3.7626
0.2011382 3.7683
0.201915434 3.7665
0.202310538 3.7599
0.203258508 3.7656
0.204153451 3.7569
0.204903352 3.753
0.205311089 3.7512
0.206192075 3.753
0.207033292 3.7461
0.207966146 3.7539
0.208478393 3.7473
0.209318747 3.7425
0.210119413 3.7455
0.21077548 3.7443
0.21140512 3.7425
0.21234924 3.7443
0.213122589 3.7461
0.213751552 3.7443
0.214498207 3.7422
0.215192234 3.7425
0.216030006 3.7395
0.216762788 3.7437
0.217508397 3.7377
0.218096851 3.7446
0.223098604 3.7383
0.219547672 3.7386
0.220187807 3.7395
0.220906094 3.7386
0.221872127 3.7368
0.222381072 3.7404
0.223111647 3.7374
0.223789808 3.7365
0.224207027 3.7278
0.225288796 3.7359
0.225862032 3.7326
0.226487197 3.7368
0.226396039 3.7302
0.227775995 3.7308
0.228426593 3.7287
0.229115997 3.7278
0.229063975 3.7269
0.230312139 3.726
0.23101389 3.7104
plot(x,y)
Can you please give me suggestions of models (I've tried polynomials and I either get a bad fit or a overfit). Thanks!
Just monkeying around in Python/Numpy for a few minutes, it looks like you want a formula like
Yfit(x) = Ymax * (1 - exp(-(x-x0)/a) )
x0 is where the data starts to take off from zero. Looks like x0 = 0.012 give or take a little. Ymax is the maximum value. The parameter a sets how fast the curve rises, and it look like you want a = 0.007 or so.
Polynomials are bad for any data that levels off and holds steady before or after the interesting parts. Polynomials like to wiggle, like a snake trying to go through lined-up croquet wickets. Even fitting loosely with least-squares or whatever, polynomials don't like flatness. But the shape sure looks like a constant minus a decaying exponential - very common in electronics and physics.
The initial zero values, I take to be meaningless and not needing fitting. The Yfit values you get could be clipped to zero when negative, for plotting and comparison.
If exp(-(x-x0)/a) doesn't work well enough, you could try other functions that quickly fade to zero, such as 1/(1+x^p) for some power p>=2, or use a Gaussian exp(-(x-x0)^2 / a^2)
I actually see a slight curve - the Y values go up to max, and then slightly back down. Maybe add a quadratic term to your model, like:
Y_extra_term(x) = ((x-xmax)/b)^2
where xmax is the x value where y is maximum.
(BTW, I'm no expert on R, so use the correct syntax not whatever I write.)

Resources