Can the parameter epsfcn be specified in lmfit to approximate the Jacobian? - lmfit

I want to specify the epsfcn value for the leastsq option in lmfit. Can the epsfcn value be specified?

Let me answer my own question. The keyword argument espfcn can be added to the minimize function and is automatically passed on to the leastsq function. I hadn't seen that in the documentation of the minimize function. It works great.

Related

Modelica: check equality of replaceable package or model

In my Modelica system model, I have a replaceable package (medium, fluid properties) and a replaceable model (pressure loss model). Can I somehow check whether a certain model or package is selected? The following approach does not work, but maybe explains what I want to achieve:
replaceable package Medium = Modelica.Media.Water.WaterIF97_ph;
Boolean isWater = (Medium == Modelica.Media.Water.WaterIF97_ph);
I was thinking of something similar like in python, were you can use type(variable) or isinstance(object, class). This approach seems to be doable in many languages, but is it possible in Modelica?
One workaround I thought of was to add some (or use an existing) constant inside the replaceable model/package and use that in the comparison, e.g. constant String mediumName or constant Integer correlationID, but I would see that as a workaround.
The workaround seems to work when using Integers, but not when using Strings. Any comment?
With comparison of constant Integer, I can calculate the correct value for the Boolean, but I hit another problem (in Dymola at least): When I use the Boolean in the annotation Dialog enable, it does not work. Is there a rule when the value of the Boolean gets evaluated?
The medium packages already have a property mediumName that you can compare, for instance using the code:
Boolean isWater = Modelica.Utilities.Strings.isEqual("WaterIF97", Medium.mediumName);
Best regards,
Rene Just Nielsen

Should a ! function return anything?

In the style guide it says that functions that modify their arguments should be marked with a !. However in the example given the function double! returns the modified argument a. Why return it if it has already been modified? Is it necessary?
It doesn't cost anything and enables you do things like:
b = double!(a)*x
or
double!(double!(a))
in a single line if you needed to.
For that reason (i.e. convenience), it has become convention.

Observable.zip does not call subscribe.next if sources are given as array

I have a two dimentional array of BehaviorSubject<number>s. For debugging purposes I want to write the values in a formatted manner as soon as all the array cells emit value. So I wrote this:
Observable.zip(universe.map(row => Observable.zip(row)))
.takeUntil(stopper)
.subscribe(u =>
console.log(`[\n\t[${u.map(r => r.toString()).join("],\n\t[")}]\n]`))
Nothing written. And also this hasn't work:
Observable.zip(universe[0])
.takeUntil(stopper)
.subscribe(u => console.log(`1[${u.toString()}]`))
But these following worked (the array has 5 columns):
Observable.zip(universe[0][0], universe[0][1], universe[0][2], universe[0][3], universe[0][4])
.takeUntil(stopper)
.subscribe(u => console.log(`2[${u.toString()}]`))
Observable.zip(Observable.zip(Observable.zip(Observable.zip(universe[0][0], universe[0][1]), universe[0][2]), universe[0][3]), universe[0][4])
.takeUntil(stopper)
.subscribe(u => console.log(`3[${u.toString()}]`))
Also I have considered .zipAll() operator but there is no document about it.
This may be a bug in Observable.zip() code as it shows ArrayLike<BehaviorSubject<number>> as possible argument type in code assistance.
So is there any other way to get this functionality? How can I get the array values written down once all of the values are reassigned, without knowing the actual dimensions of course?
The important thing is that zip() operator doesn't take an array of Observables but an unpacked series of Observables instead.
That's why Observable.zip([obs1, obs2, obs3]) doesn't work.
But Observable.zip(obs1, obs2, obs3) works.
It's not possible to help you when we don't know what universe is. From what you have now it seems like you could use destructuring assignment (assuming you're using ES6 or TypeScript):
Observable.zip(...universe[0]);
I don't know what plans are with zipAll() but right now it just callls zip().
As of rxjs#5.0.3 Observable.zip() function implementation does not recognize Observable arrays even though export declare function zipStatic<T>(array: ObservableInput<T>[]): Observable<T[]>; and export declare function zipStatic<T>(...observables: Array<ObservableInput<T>>): Observable<T[]>; function declarations take place in rxjs/operator.zip.d.ts (What is the difference between this declarations is beyond my Type/Javascript knowledge). It simply pumps the argument object members passed to it to a local array and never flattens them if you pass array. And even does not check parameter types to raise the situation.
After receiving #martin's answer above, I changed the calls to Observable.zip() with Observable.zip.apply(null, observable_array) then the problem is solved. But .zip() should accept (at least one) array of Observables in order to help readability and adhere to aforementioned function declarations.

ReSharper: Find Usages of an optional parameter

If I have a function with optional parameter, is there an easy way to find all the locations in my code that call that function and pass a value to that parameter?
The function has many non-default parameters, so scanning the usual Find Usages results of places that call the function is problematic, as it trims the lines and I can't see if the optional parameter is used.
With your cursor on the parameter, choose ReSharper | Inspect | Value Origin, or from the keyboard, Inspect This with Ctrl+Shift+Alt+A, then Value Origin.
You will get an Inspection Results window with all the places that explicitly assign that parameter a value.
I think the best way is changing Signature of the method. In other word you can change type of the parameter to another type (that is not used by parameters for safety) and see Errors list after rebuild.
By this way you can find all (not only explicitly) usages of the parameter.

Best practice for validating Input variables in Boolean functions

At work we often use functions returning a BOOLEAN where the BOOLEAN represents a logical statement and not whether the operation of the function was successfully or not
e.g. BOOLEAN HaseThisValueBeCountedAlready (Value)
When validating the input in this function what would be the best way proceed if invalid input was detected. Some people think to just return FALSE but in my opinion that would just hide the fact that something is wrong and the Caller might proceed doing something with the value not knowing that the answer doesn't make sense.
The function might be globally accessible so it feels a bit weird assuming the caller will validate the input.
Any ideas?
In general, for invalid input that doesn't enable the functions to provide the service/answer, you need to raise an exception.
This way, the guy asking the "question" to the function knows he's not "formulating" it the right way.
if its a value that need to be read periodically , you can assign the output to a global variable ,if it valid or dont update global variable if the input is invalid , so the global variable stays with the previous valid value.
this way , each function need this value , use the global variable with 100% that is valid value.

Resources