Where should i locate the setpoint change in the python code; after or before solving the MPC(m.solve(disp=True))? [closed] - gekko

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am trying to use GEKKO to control the concentration and temperature of a CSTR while manipulating the cooling temperature and the inlet flow. I am confused about the position of the setpoint change in the python code. In one example on the APMonitor website, the setpoint of the controlled variables were put before the mpc solve option; that was used when m.options.CV_TYPE was equal to 2. One another case was when m.options.CV_TYPE was equal to 1 and the setpoint change was put after the mpc solving option.
Thank you.

Basically, the setpoint sequence should be located before the solver execution command (m.solve()) regardless of the CV_TYPE.
However, if your code wrapped by 'For' loop for the realtime execution, the location of setpoint sequence can be either before and after the 'm.solve()' command depending on how you structure the 'For' loop.
I think all the CSTR example code in the below website have 'For' loop. So, that might be a reason for the variation of location.
http://apmonitor.com/do/index.php/Main/NonlinearControl

Related

How does Ruby generate random numbers using [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
So when using, for example, rand(10), how does ruby generate the random number? I have very little knowlege about random number generation techniques, so I would like to get to know them better.
Ruby is open-source. I'll demonstrate how to locate the PRNG (pseudo random number generator) code, as there's no way to generate truly random numbers using a deterministic CPU.
Looking at the repository, we see a suspiciously-named file, random.c. Looking inside, it's in C, but that's ok, it has comments. The first function is genrand_real, calling genrand_int32, which takes a struct MT. This function is defined in mt19937.c and looking at that file, it uses bitwise operations to get the next state of the random number generator and applies more bitwise operators to generate the number desired.

Machine learning and actual predictions [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have a question about machine learning regarding predictions.
So typically I would have a dataset with x's and y's that i would train my algo on. But what if I just have a dataset with input variables only (x's) and no actual predictions (y's)?
For example, im looking for fradulent transactions.
In dataset A i have a bunch of input variables like amounts, zipcodes, merchant, etc. and i have a fraud status variable that says 1 for possible fraud, 0 for safe transaction. Here i have known frauds/known non frauds that i can train my model on.
However, what if i have a dataset where there is no fraud varaible. All i have is my input variables and no variable that indicates whether it is fraud or not. How could an ML algo then predict the probability of it being a fraudulent transaction for this specific dataset?
I think what you are looking for is anomaly detection. In anomaly detection, you will try to find the datapoints, which are different from the rest of the data points, in your case it is fraudulent transaction.
There are quite a few algorithms available in sklearn, look here. I would recommend start with IsolationForest model for your problem.
From Documentation.

What is the function of state in a pseudorandom number generator? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm working on a pseudorandom number generator for an assignment and I'm having a hard time wrapping my head around how state is used in it. What does it mean to advance to the next one? I'm not looking for tips on implementation, just an explanation of the concept. Thanks!
A PRNG generates a sequence of numbers.
To calculate the next number, you have some internal state (variables set to specific values, if you will). That's the state referred to in the context of PRNG. This state can often be represented by just a single number.

how to efficiently work through algorithms on paper [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I am currently reading a programming text book and as I discover different algorithms used in the book I'm finding it necessary to understand how they work by working through them. Is there a standard & efficient way to work through simple algorithms on paper?
Write the algorithm down on the paper. Write the corresponding graphs and variables that you use in algorithm.
Now follow algorithm step by step and note what changed with variables and graphs etc.
Time slices. Make a table, where the column headers are variables involved, and row headers are step numbers. Fill in row zero with initial values if any, and each row represents the result of the current step on the previous row.

How to create a function that returns a random number from the LEVY distribution in Lua? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
As the title says, is there an easy function I can make in Lua that draws a random number based on the Levy probability density function?
I'm planning on using Levy-flight to make particles explore (make large steps) in a search space more efficiently.
Use rejection sampling on the graph of the Lévy PDF [answer from user: lhf]
Example of code:
function rejectionSampling()
repeat
local x = random.uniform(1)
local y = random.uniform(1.5) -- PDF maximum peak at x=1/3 --> y~1.45
fx = math.sqrt(1/(2*math.pi))*math.exp(-1/(2*x))/(x^1.5) --PDF
until y < fx
return x
end
Use rejection sampling on the graph of the Lévy PDF.
one solution could be :
give a lecture to John Nolan RobustAnalysis
buy/try the C library, here is the documentation.
use luaJit ffi library and map c functions and data structure to lua.
...it's no difficult but you need time.
Outside lua (yes I know the question was on lua), but you could try an interaction between lua and Wolfram Mathematica, where stable distribution are built-in.

Resources