plotting a function defined by parametric integral - integral

I am going to plot2d the function f(x) which is defined by a parametric integral
load("c:/work3/nint.mac");
g(x,y):=x*y;
f(x):=nint(g(x,t),t,1,100);
wxplot2d(f(x),['x,0,10]);
plot2d: expression evaluates to non-numeric value everywhere in
plotting range.

Related

Particle swarm optimization and function with several parameters

I would like to optimize a function with several parameters using Particle swarm optimization. How can i do it? Everywhere I found this formula 1, but how can I understand this formula, I can optimize a function with only one variable. For example, I have a function with 2 parameters and I want to maximize it. How can I do it with PSO?
vi,d ← ω vi,d + φp rp (pi,d-xi,d) + φg rg (gd-xi,d)
function (x, y)
{
return x + y
}
Since you have just 2 variable to optimize, your search space would be two dimensional. Assume that you want to optimize parameters x1 and x2. Furthermore, x1 is in the range of [a1,b1] and x2 is in the range of [a2,b2]. First you need to initialize a random population of particles (say 30 particles) into the search space boundary and assign random values to velocity vectors (V). Afterwards, you need to evaluate the fitness of the all particles and determine the best particle (Global best). Then you should perform the main upading mechanism of PSO.
This link would be helpful:
http://yarpiz.com/50/ypea102-particle-swarm-optimization

Plotting two variables function

This question is for learning purpose. I am writing my own function to plot an equation. For example:
function e(x) { return sin(x); }
plot(e);
I wrote a plot function that takes function as parameter. The plotting code is simple, x run from some value to some value and increase by small step. This is plot that the plot() manage to produce.
But there is the problem. It cannot express the circle equation like x2 + y2 = 1. So the question would be how should the plot and equation function look like to be able to handle two variables.
Noted that I am not only interesting in two circle equation. A more generalize way of plotting function with two variables.
Well to plot a non function 1D equation (x,y variables) you have 3 choices:
convert to parametric form
so for example x^2 + y^2 = 1 will become:
x = cos(t);
y = sin(t);
t = <0,2*PI>
So plot each function as 1D function plot while t is used as parameter. But for this you need to exploit mathematic identities and substitute ... That is not easily done programaticaly.
convert to 1D functions
non function means you got more than 1 y values for some x values. If you separate your equation into intervals and divide to all cases covering whole plot then you can plot each derived function instead.
So you derive y algebraicaly (let assume unit circle again):
x^2 + y^2 = 1
y^2 = 1 - x^2
y = +/- sqrt (1 - x^2)
----------------------
y1 = +sqrt (1 - x^2)
y2 = -sqrt (1 - x^2)
x = <-1,+1>
this is also not easily done programaticaly but it is a magnitude easier than #1.
do a 2D plot using equation as predicator
simply loop your view through all pixels and render only those for which the equation is true. So again unit circle:
for (x=-1.0;x<=+1.0;x+=0.001)
for (y=-1.0;y<=+1.0;y+=0.001)
if (fabs((x*x)+(y*y)-1.0)<=1e-6)
plot_pixel(x,y,some_color); // x,y should be rescaled and offset to the actual plot view
So you just convert your equation to implicit form:
x^2 + y^2 = 1
-----------------
x^2 + y^2 - 1 = 0
and compare to zero with some threshold (to avoid FPU accuracy problems):
| x^2 + y^2 - 1 | <= threshold_near_zero
The threshold is half size of plot lines width. So this way you can easily change plot width to any pixel size... As you can see this is easily done programaticaly but the plot is slower as you need to loop through all the pixels of the plot view. The step for x,y for loops should match pixel size of the view scale.
Also while using equation as predicate you should handle math singularities as with blind probing you will most likely hit some like division by zero, domain errors for asin,acos,sqrt,etc.
So for arbitrary 1D non function use #3. unless you got some mighty symbolic math engine for #1 or #2.
Defination of a function : A function f takes an input x, and returns a single output f(x).
Now it means for any input there will be one and only one unique output. Like y = sin(x). this is a function on x and y definnes that function.
For equaltion like (x*x) + (y*y) = 1. there are two possible values of y for a single value of `x, hence it can not be termed as a valid equaltion for a function.
If you need to draw it then one possible solution is to plot two points for a single value of x, i.e. sqrt(1-(x*x)) and other -1*sqrt(1-(x*x)). Plot both the values (one will be positive other will be negative with the same absolute value).

Is the derivative of the sigmoid function always the same regardless of its inner variables?

The derivative of the sigmoid function is:
df(sigmoid(x)) = sigmoid(x) ( 1 - sigmoid (x))
Is this always true no matter what 'x' is? I'm calculating a back propagation of a CNN by hand and it seems that way with my output function being sigmoid solving for the gradients W0, P, etc.
Thank you.

Maintaining state in a HIVE query

I wrote a user-defined-function (UDF) that returns true iff the input point (x,y,z) is on plane P.
The function IsOnPlane gets the x,y,z coordinates of a point, and an index of the plane id P as an input.
For example, if P is the plane spanned by {(0,0,1),(0,1,0),(0,1,1)} then :
IsOnPlane(0,700,2, P)=TRUE and IsOnPlane(1,2,3, P)=FALSE
The planes are represented as the coefficient of the plane equation:
Ax+By+Cz+D=0
In order to implement the IsOnPlane function, I am using a different representation of plane (spanning vectors).
Is there a way to do the conversion once and store it in memory, and then use it to evaluate the return value of the function each time the UDF is called ?

Image processing with z transform

I am implementing the z transformation and I am using the built-in function ztrans in Matlab. Now i give
x=imread('lena512.bmp');
x=im2double(x);
z=ztrans(x);
where x contains the pixel values of an image and ztrans(x) should apply z-transformation. But i am getting an error like this
??? Undefined function or method 'ztrans' for input arguments of type 'double'.
How can I use the function and apply z transformation on images?
Z = zscore(X) returns the z-score for each element of X such that columns of X are centered to have mean 0 and scaled to have standard deviation 1. Z is the same size as X.
so in order to do what you wanted you should use this instead
x= zscore(x)
imshow(x,[])
keep in mind that this will give you some weird results as this is done for each column, to create a global transformation you should do the following
[m,n]= size(x)
x= zscore(x(:))
x = reshape(x,m,n)
imshow(x,[])
enjoy
enjoy

Resources