Non-evolutionary optimization

Hello,

I would like to maximize an indicator with only one slider as a parameter.
I know that there’s only one solution which can be found by gradually increasing parameter value until it gets to the best value possible (the one that maximize the fitness parameter) like shown in the image.

graph
I tried to do it with Galapagos but the evolutionary method, even though it gives good results, is far from optimal and tends to be time-consuming …

I was wondering if anyone knew a way to do it ?

Thank you in advance !

Angle based tensegrity cell.gh (17.1 KB)

Fore cases like this I developed my own stepper driver which converges at a threshold value (which can be based on a “fitness” value). But the logic for that value is up to you to figure out (but you could collect result values in a list, then sort them and pick the best value as the “fitness” value. for example).

The MaxNumSolver(s) supports watching, and converging, at multiple downstream values (why waste your time running them one by one if they solve different non-dependent problems, like finding a bunch of “solution candidates” for different approaches etc).

I also made a VS version of this (which is included in a GH plugin though), but I can’t remember if I made any bugfixes on this script-component version, but the example provided in this definition seems to work:

RE_MaxNumSolver.gh (18.9 KB)

3 Likes

This is a generic problem with non-deterministic methods; They can’t (or should’nt) be used for “production” solutions, which typically needs to be deterministic, and as you indicated, much faster. Or in other words, the end result really must be designed, implying a goal being based on some critical degree of foreknowledge.

How that foreknowledge is gained is another matter altogether. To clarify the reasoning I want to point out that earlier exploratory stages may well make use of non-deterministic methods, like for finding sensible boundaries for which a final (designed) solution is targeted with deterministic methods (like, finding target values within a known specific interval, with predefined step-sizes etc, which is what the basic idea was with the redneck solution which I called “MaxNumSolver”).

// Rolf

1 Like

Whenever you have a single slider it is better to remove the slider and give a wide range of values.
Then get the optimized value get its index from the list and use the index to get the input value that produced it.

image

Angle based tensegrity cell_trial01.gh (18.4 KB)

1 Like

Hi Alexandre,

Here is another method that I use for optimization when there’s only one parameter:
-Divide the parameter domain into n equal segments and generate a range of values.
-Generate a solution for each value in the range.
-Generate points with the values from the range as X, and the corresponding solutions as Y coordinates.
-Interpolate the points to create a curve that represents the solution set.
-Find the extremes of the curve.

By that method, I managed to find optimal angle as 29.998832 when n is 10. The bigger the n, the better the result.

Find the gh definition attached.Angle based tensegrity cell_NON_EVO_OPT.gh (21.0 KB)

Best,
Tolga

1 Like

Yep, interpolating a curve is a better solution, though still inacurate as the spline curve wiggles between the points.

In this case I guess your best chance is using dynamic relaxation - Kangaroo.

It will allow giving wrong results left and right until it finds the smallest value.

I actually think Goat is closest to what you want here


You connect it to sliders and an output value to min/max just like Galapagos, but it’s deterministic, and converges much faster than an evolutionary method for this sort of simple problem, yet still doesn’t require that you know a function for the gradient.

Kangaroo can be faster still for some types of problem, but requires that the thing being optimised can either be defined with a combination of the included goals, or you can write a function for the gradient as a custom goal.

I believe there’s also a completely non-iterative solution to this particular problem too - just using trigonometry. I’m guessing though that you are showing this just as a simpler example, and are actually interested in a more general method, in which case iterative numerical optimisation does make sense.

4 Likes

Thank you everyone for your suggestions !

I initially tough of some recursive code inside the script to find the solution with dynamic increment to find the best solution unfortunately grasshopper doesn’

It seem to support recursive definitions :sweat_smile:

I guess I’ll use a range of value (which actually gives good approximation) :smiley: based on all these scripts ? @RIL would you mind if I use or slightly modify your solver for my master thesis ?

@DanielPiker Thank you ! This is exactly what I was looking for in first place !
There’s indeed a simple analytic solution for this particular problem. But as you’ve guessed it’s part of more complex structures and I, yet, haven’t found a better solution than numerical optimization (which I actually don’t know how to do for the moment) :grin:

I’m actually using kangaroo to create this kind of structures but the results aren’t great with all the structures I try to optimize :sweat_smile: … Maybe I should try to redefine my goals by looking at all the other possibilities and in particular dynamic relaxation which I have never heard of … :grinning:

Dynamic relaxation is just a name for the method used by Kangaroo to find structures in equilibrium.

If you have examples where you’re trying to use Kangaroo and aren’t getting the results you expect, you can post them here. Often form-finding tensegrity structures can be as simple as modelling the approximate geometry, then assigning a pre-tension to the cables and making the struts stiff. If you are starting very far from an equilibrium position though you might need a bit more.

Also - depending on how you are fabricating them, you might need to actually calculate the slack length for the cables after the form-finding step.
For medium sized structures with something fairly inelastic like wire for the tensile elements, you can probably just take the lengths directly from the output of the form-finding, or scale them by some factor slightly less than 1 for pre-tension.
For larger structures though, or if using more stretchy material for the cables, then to get the same geometry you need to calculate how much each cable should increase in length, and I can share some example files for this if you need.

1 Like

There is a simpler way to approximate the gradient of any continuous function: (F(x+h) - F(x))/h, where h is a value close to 0. Given a fitness function, you evaluate it in x in at x+h, and you can measure how it will change. If the fitness decrease, then move x backwards, if x+h is more apt, move it forward, iteratively until it converges into an acceptable error.
Here is a quick implementation using Anemone. Now I don’t have time to make it robust, but the main idea is there.

Angle based tensegrity cell.gh (31.2 KB)

2 Likes

Specifically, for this type of “convex” problem, the local BOBYQA and COBYLA in Goat should work very well.

2 Likes

Thank you very much ! I didn’t know it was possible to create loop, as I’ve been facing that circular references lead to errors !

I can confirm by trial and error, BOBYQA and COBYLA are the two best options ! :smiley:

I’m actually struggling a bit to create an efficient script that create assembly of tensegrity cells …
I’m trying to vary the thickness of the assembly as well as the height thus leading to a specific ratio between compressed and tensile elements for each level of the assembly :sweat_smile:

I obtain some results by using a unique big ratio, but it makes the structure kind of inflating … Ideally, the best way to achieve good optimization of ratio would be maximizing the length of compressed element (in red in the script) with respect to the length goals of the other elements. But I can’t find a way to do it :thinking:

Node on node non-regular tensegrity.gh (25.9 KB)

1 Like

No problem, go ahead.

Perhaps I should point out that the MaxNumSolver approach is best suited for repeated tasks, which doesn’t suffer from local optima but instead having a convex result curve (like the one you posted). For repeated “heavy” tasks it is a big advantage to start the solver near a foreknown solution interval, and terminate as soon as a goal is reached. For one-off solutions number series is just as good or better since it can detect local optima, if any. So, the MaxNumSolver, although it supports “looping” (reacting on downstream values), it isn’t useful unless you know that you always have a convex result curve.

// Rolf

3 Likes

goat sounds interesting so I tried to install it, but Norton Security quarantines and removes the code from both food4rhino and rechenraum.com

Filename: f_015e94
Threat name: Heur.AdvML.CFull Path: C:\Users\xyz\AppData\Local\Google\Chrome\User Data\Default\Cache\f_015e94



On computers as of
9/6/2019 at 9:36:09 AM

Last Used
9/6/2019 at 9:38:09 AM

Startup Item
No

Launched
No

Threat type: Heuristic Virus. Detection of a threat based on malware heuristics.


f_015e94 Threat name: Heur.AdvML.C
Locate

Few Users
Hundreds of users in the Norton Community have used this file.

Mature
This file was released 2 years 10 months ago.

High
This file risk is high.


https://www.rechenraum.com/en/assets/downloads/goat/goat-3.0-setup.exe
Downloaded File from rechenraum.com
Source: External Media

f_015e94


File Actions

File: C:\Users\xyz\AppData\Local\Google\Chrome\User Data\Default\Cache\ f_015e94 Removed


File Thumbprint - SHA:
2ba195174c4bfaa04678e26b7df72f315df716f8b06e6986866f63f212d675ff
File Thumbprint - MD5:
05630f470907351f0f1b268fe626260b

No threat for this file indicated by BitDefender or MalwareBytes. Could be a false positive, but how would we get to know if so?

// Rolf

for what it’s worth, it was blocked here as well, (Symantec Endpoint Protection).

Google “Heur.AdvML.C” or “Heur.AdvML.C false positive”.

I’ve been using Goat for years and personally know the developer, so I’m sure it’s not a virus.
I also know that my own plug-in (Opossum) sometimes is deleted as a virus.

1 Like

Still googling? As for me I’m quacking these days:

// Rolf

Reply from goat at rechenraum.com, which he asked me to share here:

thanks for getting back to us on that sad issue. We have been fighting false positives from antivirus software ever since switching to an automated installer. See the thread starting at post #25913 over at
goat | Food4Rhino

May I ask you to link from the discourse.mcneel.com discussion to the food4rhino discussion?

The only way to make the antivirus software happy would be to digitally sign the installer. With goat being freeware, that shifted a bit out of our focus, buying the respective certificate is not an option at the moment.

thanks, Simon