Geotools MismatchedDimensionException when using smooth() - geotools

I am experimenting with Geotools java library, and specificaly with the smooth method. In the Geotools documentation there is this example:
WKTReader reader = new WKTReader();
Geometry tShape = reader.read(
"POLYGON((10 0, 10 20, 0 20, 0 30, 30 30, 30 20, 20 20, 20 0, 10 0))");
Geometry tLoose = JTS.smooth(tShape, 0.0);
Geometry tTighter = JTS.smooth(tShape, 0.75);
when I execute this I keep getting this error:
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/opengis/geometry/MismatchedDimensionException
in line Geometry tLoose = JTS.smooth(tShape, 0.0); (same happens with next line)
Why am I getting this error?

Related

Curve Fitting past last data point(s)

I am trying to fit a curve to a set of data points but would like to preserve certain characteristics.
Like in this graph I have curves that almost end up being linear and some of them are not. I need a functional form to interpolate between the given data points or past the last given point.
The curves have been created using a simple regression
def func(x, d, b, c):
return c + b * np.sqrt(x) + d * x
My question now is what is the best approach to ensure a positive slope past the last data point(s) ??? In my application a decrease in costs while increasing the volume doesn't make sense even if the data says so.
I would like to keep the order as low as possible maybe ˆ3 would still be fine.
The data used to create the curve with the negative slope is
x_data = [ 100, 560, 791, 1117, 1576, 2225,
3141, 4434, 6258, 8834, 12470, 17603,
24848, 35075, 49511, 69889, 98654, 139258,
196573, 277479, 391684, 552893, 780453, 1101672,
1555099, 2195148, 3098628, 4373963, 6174201, 8715381,
12302462, 17365915]
y_data = [ 7, 8, 9, 10, 11, 12, 14, 16, 21, 27, 32, 30, 31,
38, 49, 65, 86, 108, 130, 156, 183, 211, 240, 272, 307, 346,
389, 436, 490, 549, 473, 536]
And for the positive one
x_data = [ 100, 653, 950, 1383, 2013, 2930,
4265, 6207, 9034, 13148, 19136, 27851,
40535, 58996, 85865, 124969, 181884, 264718,
385277, 560741, 816117, 1187796, 1728748, 2516062,
3661939, 5329675, 7756940, 11289641, 16431220, 23914400,
34805603, 50656927]
y_data = [ 6, 6, 7, 7, 8, 8, 9, 10, 11, 12, 14, 16, 18,
21, 25, 29, 35, 42, 50, 60, 72, 87, 105, 128, 156, 190,
232, 284, 347, 426, 522, 640]
The curve fitting is simple done by using
popt, pcov = curve_fit(func, x_data, y_data)
For the plot
plt.plot(xdata, func(xdata, *popt), 'g--', label='fit: a=%5.3f, b=%5.3f, c=%5.3f' % tuple(popt))
plt.plot(x_data, y_data, 'ro')
plt.xlabel('Volume')
plt.ylabel('Costs')
plt.show()
A simple solution might just look like this:
import matplotlib.pyplot as plt
import numpy as np
from scipy.optimize import least_squares
def fit_function(x, a, b, c, d):
return a**2 + b**2 * x + c**2 * abs(x)**d
def residuals( params, xData, yData):
diff = [ fit_function(x, *params ) - y for x, y in zip( xData, yData ) ]
return diff
fit1 = least_squares( residuals, [ .1, .1, .1, .5 ], loss='soft_l1', args=( x1Data, y1Data ) )
print fit1.x
fit2 = least_squares( residuals, [ .1, .1, .1, .5 ], loss='soft_l1', args=( x2Data, y2Data ) )
print fit2.x
testX1 = np.linspace(0, 1.1 * max( x1Data ), 100 )
testX2 = np.linspace(0, 1.1 * max( x2Data ), 100 )
testY1 = [ fit_function( x, *( fit1.x ) ) for x in testX1 ]
testY2 = [ fit_function( x, *( fit2.x ) ) for x in testX2 ]
fig = plt.figure()
ax = fig.add_subplot( 1, 1, 1 )
ax.scatter( x1Data, y1Data )
ax.scatter( x2Data, y2Data )
ax.plot( testX1, testY1 )
ax.plot( testX2, testY2 )
plt.show()
providing
>>[ 1.00232004e-01 -1.10838455e-04 2.50434266e-01 5.73214256e-01]
>>[ 1.00104293e-01 -2.57749592e-05 1.83726191e-01 5.55926678e-01]
and
It just takes the parameters as squares, therefore ensuring positive slope. Naturally, the fit becomes worse if following the decreasing points at the end of data set 1 is forbidden. Concerning this I'd say those are just statistical outliers. Therefore, I used least_squares, which can deal with this with a soft loss. See this doc for details. Depending on how the real data set is, I'd think about removing them. Finally, I'd expect that zero volume produces zero costs, so the constant term in the fit function doesn't seem to make sense.
So if the function is only of type a**2 * x + b**2 * sqrt(x) it look like:
where the green graph is the result of leastsq, i.e. without the f_scale option of least_squares.

From Action Script 2.0 to 3.0 compiling errors

From the errors above what should I change in the code? I'm new to AS3 and a point in the right direction will help a lot, thanks!
Scene 1, Layer 'Script Layer', Frame 18, Line 62, Column 19 1084: Syntax error: expecting rightparen before add.
Scene 1, Layer 'Script Layer', Frame 18, Line 62, Column 29 1084: Syntax error: expecting rightparen before eq.
Scene 1, Layer 'Script Layer', Frame 18, Line 68, Column 24 1084: Syntax error: expecting rightparen before add.
Scene 1, Layer 'Script Layer', Frame 18, Line 68, Column 48 1084: Syntax error: expecting rightbrace before rightparen.
leng = 52;
q = 0;
while(Number(q) < Number(leng))
{
rand = random(52);
if(eval("c" add rand) eq "empty")
{
q = q - 1;
}
else
{
set("shuffle" add q,eval("c" add rand));
set("c" add rand,"empty");
}
q = Number(q) + 1;
}
q = 0;
}
ShufflePloy();
I don't know much about AS2, but first I'd try changing rand = random(52); to:
rand = Math.floor(Math.random()*52);
and then if(eval("c" add rand) eq "empty")
to
if(this["c"+rand] == "empty")
and the contents of the else block to
this["shuffle"+q] = this["c"+rand];
this["c"+rand] = "empty";

Slide the popup in libgdx not work

I am trying to develop a libgdx game. i want to implement a selection screen. Till now i have implemented horizontal scrollpane and it is working fine.
Now i want to implement scrolling on the click on the button. You can check the image attached.
Try instead to use json pack
This works for me:
_skin = new Skin();
TextureAtlas buttonAtlas = new TextureAtlas("images/buttons.pack");
_skin.addRegions(buttonAtlas);
_textButtonStyle = new TextButtonStyle();
_textButtonStyle.font = _game.getFont();
_textButtonStyle.up = _skin.getDrawable("button-orange");
_textButtonStyle.down = _skin.getDrawable("button-blue");
buttons.pack:
buttons.png
size: 234,195
format: RGBA8888
filter: Nearest,Nearest
repeat: none
button-orange
rotate: false
xy: 0, 0
size: 236, 67
split: 25, 25, 14, 14
orig: 236, 67
offset: 0, 0
index: -1
button-blue
rotate: false
xy: 0, 67
size: 236, 67
split: 25, 25, 14, 14
orig: 236, 67
offset: 0, 0
index: -1
button-navy
rotate: false
xy: 0, 134
size: 236, 67
split: 25, 25, 14, 14
orig: 236, 67
offset: 0, 0
index: -1
Try in create method
yourImage = new Image(new Texture("images/image.png"));
stage.add(yourImage);
Try in render method
yourImage.setPosition(yourX, yourY)
for the answer look this link https://github.com/krustnic/HorizontalSlidingPane

Error in FUN(X[[1L]], ...) : as.edgelist.sna input must be an adjacency matrix/array, edgelist matrix, network, or sparse matrix, or list thereof

I am trying to learn few basic functions in Igraph- But, I am having problems computing the degrees from a gragph: see example below (I copied the following example from this site):
Example of data set:
edges <- matrix(c(103, 86, 24, 103, 103, 2, 92, 103, 87, 103, 103, 101, 103, 44), ncol=2, byrow=T)
Create graph
g <- graph(as.vector(t(edges)))
I can compute the degrees from the matrix edges:
degree(edges)
[1] 378 254 210 390 380 408 294 1230 1084
But I cannot compute the degrees from the graph g:
degree(g)
I am getting the following error:
Error in FUN(X[[1L]], ...) :
as.edgelist.sna input must be an adjacency matrix/array, edgelist matrix, network, or sparse matrix, or list thereof.
Anyone knows why I am getting this error?
So what happened here is igraph::degree is masked by sna::degree.
Just use:
igraph::degree
and it should work
I ran into same issue.
This worked for me:
net <- make_ring(10)
deg <- centralization.degree(net)$res

Can't read previously saved data from *.m files

[layer1 layer2 layer3] = trainNeuralNetwork4L(tlab, tvec, clab, cvec, 150, 100, 10);
save layerOne100SECOND.m layer1
save layerTwo100SECOND.m layer2
save layerThree100SECOND.m layer3
[efficiency errorsMatrix] = testClassifier4L(layer1, layer2, layer3, 150, 100, 10, tstv, tstl)
1 min 55 s
efficiency = 0.96150
[....]
load "layerTwo100SECOND.m"
layerTwo100SECOND
parse error near line 6 of file /home/yob/studies/rob/lab5/src/layerTwo100SECOND.m
syntax error
>>> 0.3555228566483329 1.434063629132475 0.3947326168010625 -0.2081288665103496 2.116026824600183 -3.72004826748463 -5.971912014167303 -1.831568668193203 -0.5698533706125537 -0.302019433067382 2.105773052363495 -1.386054572212726 1.379784981138861 2.086342965563345 1.686560884521974 1.501297857975125 5.491292848790862 -3.068496819708705 1.709375867569474 -0.0007631747244577478 -3.408706829842817 3.633531634060732 -4.848485685095641 -7.071386223304461 1.005495674207059 1.729698733795992 1.332654214742491 -2.757799109392227 0.5703177663227227 -3.962183321109198 -1.862612684812663 0.002426506616464667 -1.0133423788506 0.9856584491014603 3.261391305445486 -0.238792116035831 7.213403195852512 -0.4550088635822298 2.014786513359268 5.439781417403554 -1.780067076293333 -1.141234270367437 -3.716379329290984 1.329603499392993 0.6289460687541696 1.38704906311103 -1.799460630680088 -1.231927489757737 -1.199171465361949 6.464325931161664 0.7819466841352927 1.518220081499355 -0.3605511334486079 6.646043807207327 -1.885519415534916 1.164993883529136 -0.6867734922571105 -3.487015662787853 0.6052594571214193 0.9747958246654298 -6.681621035920442 6.539828816493673 0.4174688104699146 1.804835542540412 3.099980655618463 0.1957057586983393 -0.5199262355448695 -0.05556003295310553 0.5458621853042805 4.053727148988344 5.08596174444348 -4.4719975219626 4.718638484049811 4.579389030123606 -0.3683947372431971 0.9758069969974679 0.4742051227060113 6.761326112144753 0.9816521216523206 1.790072342537753 0.4513686207416066 -2.880053219384659 -3.256083938937911 3.099498881741825 -0.4967119404782309 -0.6140345297878478 -0.9933076418596357 7.522343253108136 4.93675021253316 -2.693878828387868 -1.358775970578509 -0.7940899801569826 4.867002040829598 4.418439759567837 -2.014761152547027 0.2349575211823655 -4.494720934106189 -2.674441246174409 -0.8495958842163256 0.1921793737146104
^
Why is it impossible to use previously saved data? Is there any way to use them one more time?
Ok, I dealed with it. I had to call: load -ascii filename.