# Smooth Signal Correlation

**URL:** <https://discourse.julialang.org/t/smooth-signal-correlation/67055>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [August 26, 2021, 7:19pm UTC](https://discourse.julialang.org/t/smooth-signal-correlation/67055 "2021-08-26T19:19:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![user1200](https://avatars.discourse-cdn.com/v4/letter/u/b2d939/32.png) [@user1200](https://discourse.julialang.org/u/user1200)\
**Post date:** [August 26, 2021, 7:19pm UTC](https://discourse.julialang.org/t/smooth-signal-correlation/67055/1 "2021-08-26T19:19:47Z")

</div>

Hello  
I wanted, to smooth data signal.

For example, using mean

> y[1]=(a[1]+a[2])/2

it is

```julia
y[1]=0.5*a[1]+0.5*a[2]
y[2]=0.5*a[3]+0.5*a[4]

```

But in specific way, that new signal (y), need to have some attributes:  
for example, linear relationship

`y[2]=0.235*y[1]`

I tried other obj function with jump ipopt nlexpression, but optimization says always optimal solution found 0 in 1 step

Is there a way to compose original signal into new one containing “required atributes” ?

_Background:_  
_In R, there is function decompose, which create vector cotaining seasonality, then remainder=original vector-seasonality. Problem is, reminder has sometimes poor autocorrelation, which can leads to even more non-smooth signal, than original ._  
_Similar, smoothing data via mean-ing sometimes results in smooth vector, but if it contains poor autocorrelation, smoothed signal is “nonstructural”_  
_I was wondering, if it is possible to calculate/model similiar tasks in julia including customization._

Thanks alot

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [August 26, 2021, 7:52pm UTC](https://discourse.julialang.org/t/smooth-signal-correlation/67055/2 "2021-08-26T19:52:53Z")

</div>

> [@user1200](#):
>
> I tried other obj function with jump ipopt nlexpression, but optimization says always optimal solution found 0 in 1 step

Can you provide a reproducible example of your code?

---

<div class="post-metadata">

**Author:** ![user1200](https://avatars.discourse-cdn.com/v4/letter/u/b2d939/32.png) [@user1200](https://discourse.julialang.org/u/user1200)\
**Post date:** [August 26, 2021, 8:04pm UTC](https://discourse.julialang.org/t/smooth-signal-correlation/67055/3 "2021-08-26T20:04:22Z")

</div>

hi mr. odow, yes gladly: 🍃

> data - vector of floats

new signal is

> y[1]=x1[1]\*data[1]+x1[2]\*data[2]

attribute (obj function) is

> maxumize sum  
> tanh(x2[1]\*y[i-1]) \* y[i]

_complex goal is_  
`tanh(x2[1]*y[i-1]+x2[2]*y[i-2]+ ... ) * y[i])`

so it is simplified, but its based on good core

```julia
using JuMP
using Ipopt

model = Model(Ipopt.Optimizer)

S=2 #
D=3 #line

@variable(model, x1[1:S])
@variable(model, x2[1:D])

@NLexpressions(model, begin
        y[i=1:3000], sum(data[2*(i-1)+1+j]* x1[j+1] for j=0:1 )
    end)

@NLobjective(
        model,
        Max,
         sum( tanh(x2[1]*y[i] ) *y[i+1] for i = 3:100 ) #just for 100 points
)

optimize!(model)
print(objective_value(model))

```

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [August 26, 2021, 11:07pm UTC](https://discourse.julialang.org/t/smooth-signal-correlation/67055/4 "2021-08-26T23:07:07Z")

</div>

Ipopt assumes the problem is convex, so it will stop when it finds a local minima/maxima. This problem has a local maxima at the default starting point `x1 = x2 = 0`.

You can try different starting points:

```julia
@variable(model, x1[1:S], start = 1.0)
@variable(model, x2[1:D], start = 1.0)

```

But I think a bigger issue is that your formulation doesn’t seem correct.

Why `max`? Can’t I just make the objective arbitrarily big by increasing `y[i]`?

---

<div class="post-metadata">

**Author:** ![user1200](https://avatars.discourse-cdn.com/v4/letter/u/b2d939/32.png) [@user1200](https://discourse.julialang.org/u/user1200)\
**Post date:** [August 27, 2021, 3:30pm UTC](https://discourse.julialang.org/t/smooth-signal-correlation/67055/5 "2021-08-27T15:30:34Z")

</div>

Yes. I forget to mention  
data is similiar to random floats around 0 (like random function - sum is 0, no autocorrelation allowed

_That start parameter is helpful 🍃_ thank you
