I have simple objective function (goal), solving with Ipopt
for example:
Min, sum (sin(data[i]*x) for i=1:length(data) )

I was just curious if there is some way/wrap to achieve :
maximize linearity of process to goal.

Like in this example obj is Min, sum - so process is simple cumsum.
Reason behind this is to work with trajectory (process), for example finding path which looks (the most) like “line”.

I tried like “distance between process’s segments”, but it doesnt seem to work in Ipopt.
(I found some math hints but too math :blush:

Hi there.

I tried like “distance between process’s segments”

Take a read of Please read: make it easier to help you. It’s easier to help if you can provide the code as a minimal working example.

maximize linearity of process to goal

Can you clarify what this means?


Thanks, yes:
Code is

using Random
using JuMP
using Ipopt
data = randn(n)
model = Model(Ipopt.Optimizer)
@variable(model, x)
@variable(model, a)	#max distance
@NLexpressions(model, begin
        y[ii=1:10], sum(	sin(x*data[i]) for i = 1+floor(Int,(n/10)*ii-1):floor(Int,(n/10)*ii)   	 )	# 10 segments y[1:10] - just cumsum
        yy[ii=1:9], (-y[ii]+y[ii+1]	)^2	# just abs(distance) , but ^2
@NLconstraint(model, [i=1:9],yy[i] <= a)	#max distance , 10 segments=9 distances
#@NLconstraint(model, [i=1:9],yy[i] >= 2)	#next to implement : slope of process, each segment must raise minimum 2)
	a # minimize max distance
print(	objective_value(model)	)
value.(y) # currently zeros(10), but when slope added

Normaly I just min/max objective function, but in graph (y here) I observe sometimes very strange behaviours. So if graph of process looks like line, it would be very good.

I have other max objective function working with Ipopt. Sometimes value of y[i] jumps above global optimum, then went down.
From time perspective (y[1]…y[10]), I was curious, if there is (simplyfied :broccoli: ) way to ‘model’ graph.

(1) Current situation, ignoring graph, only min/max obj (newest y[10]
(2) Better graph
*(3) Line graph
*(4) Best line graph with high obj
( * good solutions)

I still don’t really understand the problem I’m afraid. You’re picking x that minimizes the maximum distance between two points y[i]?

Ipopt assumes the problem is convex, so using a function like sin will result in a locally optimal solution. You may see some weird artifacts. You could try multiple restarts by using @variable(model, x, start = 1.0) for different start values.