## L1 Norm Optimization Solution – Mathematics Stack Exchange

I am trying to find the solution for the following optimization problem:

$$max_{w} {z^Tw – lambda ||w – w_0||_1}$$
where $$z, w, w_0 in R^{Nx1}$$ and $$z, w_0$$ are known.

We let $$s$$ be the subgradient of $$lambda ||w – w_0||_1, hspace{2mm} s in { {u | u^T(w – w_0) = lambda ||w – w_0||_1, ||u||_{infty} leq lambda } }$$.

If we write $$lambda ||w – w_0||_1 = max_{||s||_{infty} leq lambda} s^T(w – w_0)$$, the objective function can now be written as:
$$max_{w} min_{||s||_{infty} leq lambda} {z^Tw – s^T(w – w_0)}$$
$$min_{||s||_{infty} leq lambda} max_{w} {z^Tw – s^T(w – w_0)}$$.

The first order condition for the inner objective function is:
$$0 = z – s hspace{1cm} (1)$$
Substituting (1) into the objective function,
$$min_{||s||_{infty} leq lambda} s^Tw_0$$.

Hence, this objective function can be simplified as,
$$min_s s^Tw_0 text{ s.t } -lambda leq s leq lambda$$.

However, if all the steps above are correct (which I am not very certain about), I am not sure how the solution of s from the “simplified” optimization above will help me solve for w.
The sequence of steps taken to solve the initial optimization problem was inspired by the following paper.

Any help on this is very much appreciated. Thank you.

## solution verification – Is my proof correct about the limit of this sequence?

If $$0 and $$u_{n+1}=1-sqrt{1-u_n}$$ for $$ngeq 1$$,prove that the sequence$$(u_n)$$ converges to 0.

My attempt:

First prove that $$0 by induction.
Base case: $$n=1$$, $$0 holds true.
Assume $$0.
By manipulating a bit I got $$0<1-sqrt{1-u_n}<1$$ that is $$0
Thus by induction $$0 holds true.(*)

Now

$$u_{n+2}-u_{n+1}$$=$$({1-u_{n}})^{1/2}-({1-u_{n}})^{1/4}<0$$
Thus,$$u_{n+2}
Thus, sequence is monotonic decreasing. (**)

By (*) and (**) we have,

$$0
Thus by monotone convergence theorem the sequence converges to 0.
Is this correct?

## display – Lag on external monitor using a Macbook Air 2017 with a Intel HD Graphics 6000 1536 MB and running macOs Big Sur 11.2.3: what could be the solution?

HOST MACHINE: Macbook Air 2017

GRAPHICS: Intel HD Graphics 6000 1536 MB

MACOS: Big Sur 11.2.3

Intel HD Graphics 6000:

Chipset Model: Intel HD Graphics 6000

Type: GPU

Bus: Built-In

VRAM (Dynamic, Max): 1536 MB

Vendor: Intel

Device ID: 0x1626

Revision ID: 0x0009

Metal Family: Supported, Metal GPUFamily macOS 1

Displays:
SyncMaster:

Resolution: 1920×1080 (1080p FHD – Full High Definition)

UI Looks like: 1920 x 1080 @ 60.00Hz

Framebuffer Depth: 30-Bit Colour (ARGB2101010)

Display Serial Number: H9XZ103518

Main Display: Yes

Mirror: Off

Online: Yes

Rotation: Supported

Connection Type: Analog VGA or Analog Over DVI-I

1) At home I use my mac connected to a SAMSUNG 2494HS via VGA + CableDeccon video adapter.
The default resolution is 1920×1080 at ~60HZ.

Recently ( maybe correlated to the new macOs update) I noticed some lag in the external monitor. The events occured only when I run VirtualBox (v. 6.1) and I increase the resolution: above a certain threshold the VM starts to lag.

It is not correlated to any specific VM, but is the same with any.

2) If I use the HDMI cable (whatever type) or I set ad unscaled resolution with VGA, the display looks blurry.

3) Last but not least, if I close the mac and use only the external display with the setting as 1) the VM does not lag any more.

What could be the problem and possible solutions?

I tried to unscale the resolution, use differents setting for the VM (different video adapter, memory size, processors…) but with no success.

## Linear Programming Problems with decimal solutions for problems requiring whole number solution

I have an LPP which asks for the maximum number of pairs of shoes that can be manufactured to maximize the profit. The LPP is:

Maximize Z=1350x + 975y
Subject to, 3x+1.5y&leq;275
2.5x+2y&leq;300
x, y&geq;0

The solution I obtained is x=44.45; y=94.44
Now, since x and y can only be positive integers, what will the final solution be? I’m confused about this step. Any help is welcome :-]

## differential equations – Series solution of an ODE with nonpolynomial coefficients

Basically, I have a second-order differential equation for `g(y)` (given below as `odey`) and I want to obtain a series solution at $$y=infty$$ where `g(y)` should vanish. That would be easy if the ODE contains polynomial coefficients, hence the Frobenius method can used. But in my case, the coefficients are not polynomial because of the presence of powers proportional to `p` (can take positive non-integer values). I have also expanded `ir` at infinity and have taken up to first order (given by `irInf`) since if I directly use `ir`, then it would be a mess later for the ODE.

``````ir(y_) := (Sqrt)(-5 + y^2 + (3 2^(1/3))/(2 + 10 y^2 - y^4 + Sqrt(64 y^2 + 48 y^4 + 12 y^6 + y^8))^(1/3) - (6 2^(1/3)y^2)/(2 + 10 y^2 - y^4 + Sqrt(64 y^2 + 48 y^4 + 12 y^6 + y^8))^(1/3) + (3 (2 + 10 y^2 - y^4 + Sqrt(64 y^2 + 48 y^4 + 12 y^6 + y^8))^(1/3))/2^(1/3))
dir(y_) := D(ir(x), x) /. x -> y
irInf(y_) = Series(ir(y), {y, (Infinity), 1}) // Normal

p=1/10; (*p>=0*)
odey = (2 irInf(y) - p irInf(y)^(1 - p)) D(irInf(y), y) g'(y) + irInf(y)^2 g''(y) - l (l + 1) g(y) // Simplify
``````

What steps can I take to solve this? Thanks

## differential equations – Series solution of an ODE with nonpolynomial coefficients

Basically, I have a second-order differential equation for `g(y)` (given below as `odey`) and I want to obtain a series solution at $$y=infty$$ where `g(y)` should vanish. That would be easy if the ODE contains polynomial coefficients, hence the Frobenius method can used. But in my case, the coefficients are not polynomial because of the presence of powers proportional to `p` (can take positive non-integer values). I have also expanded `ir` at infinity and have taken up to first order (given by `irInf`) since if I directly use `ir`, then it would be a mess later for the ODE.

``````ir(y_) := (Sqrt)(-5 + y^2 + (3 2^(1/3))/(2 + 10 y^2 - y^4 + Sqrt(64 y^2 + 48 y^4 + 12 y^6 + y^8))^(1/3) - (6 2^(1/3)y^2)/(2 + 10 y^2 - y^4 + Sqrt(64 y^2 + 48 y^4 + 12 y^6 + y^8))^(1/3) + (3 (2 + 10 y^2 - y^4 + Sqrt(64 y^2 + 48 y^4 + 12 y^6 + y^8))^(1/3))/2^(1/3))
dir(y_) := D(ir(x), x) /. x -> y
irInf(y_) = Series(ir(y), {y, (Infinity), 1}) // Normal

p=1/10; (*p>=0*)
odey = (2 irInf(y) - p irInf(y)^(1 - p)) D(irInf(y), y) g'(y) + irInf(y)^2 g''(y) - l (l + 1) g(y) // Simplify
``````

What steps can I take to solve this? Thanks

## Solution to Javascript coding assignment that did not get me to the interview stage

I recently completed a coding challenge for a company that did not get me to the next stage.
They were kind enough to provide the following feedback:

The coding assignment does not match what we are looking for, a mid-level Front End Engineer.
The code does not fully comply with what is asked in the assignment and the code readability is sometimes hard.

I have no problems with these criticisms as I am still in my first year as a professional developer.
However, I am really curious as to how a mid-level engineer would approach the problem. Any advice on how improve readability would also be greatly appreciated (it’s a mess in some spots I know…). I am not sure which sections they are referring to that do not comply with what is asked in the assignment.

I will list both the code and the requirements below.

## Requirements

1. When index.html is opened in the browser, the content of constant USERS in json/data.js will appear as a table on the browser. Table column order should be the same as the order already written in index.html.
• Name is the last name and the first name, respectively, separated by a space.
2. When button#start is clicked, table rows will randomly rearrange every second.
3. The process in 2 can be stopped when button#stop is clicked.
4. When user name very long (left to your own appreciation), an ellipsis is shown.
5. When button#sort is clicked, rows will be sorted by balance in descending order. If two or more balances are the same, rows will be sorted in ascending id order.
6. When the process in 2-3 is running, disable button#sort.

• Please write your code so as to avoid triggering unnecessary reflows and repaints.

… and here is the code:

### JS

``````class App {
constructor(props) {
this.startRandomBtn = document.getElementById('start');
this.stopRandomBtn = document.getElementById('stop');
this.sortTableBtn = document.getElementById('sort');
this.table  = document.querySelector('.table');
this.data = props.users;
this.active;
this.init();
}

sortTable() {
let switching, shouldSwitch, rows, i
switching = true

while (switching) {
switching = false;
rows = this.table.rows;

for (i = 1; i < (rows.length - 1); i++) {
shouldSwitch = false;
let balanceX = rows(i).querySelector('.balance').textContent
let balanceY = rows(i + 1).querySelector('.balance').textContent;
let idX = rows(i).getAttribute('data-id')
let idY = rows(i + 1).getAttribute('data-id')

if (parseInt(balanceX) === parseInt(balanceY)) {
if (parseInt(idX) < parseInt(idY)) {
shouldSwitch = true;
break;
}
}

if (parseInt(balanceX) < parseInt(balanceY)) {
shouldSwitch = true;
break;
}
}
if (shouldSwitch) {
rows(i).parentNode.insertBefore(rows(i + 1), rows(i));
switching = true;
}
}
}

setTable() {
this.data.forEach(item => {

let trNode = document.createElement('tr');

for (const key in item) {
if (key === "id") {
trNode.setAttribute('data-id', item(key))
}
else if (key === "name") {
let tdNode = document.createElement('td');
let firstName = item(key).first
let lastName = item(key).last

if (lastName.length > 11) {
lastName = lastName.slice(0,11).concat("...");
}

tdNode.textContent = `\${lastName}, \${firstName}`
trNode.appendChild(tdNode)
}
else if (key === "pictureUrl") {
let img = document.createElement('img')
img.src = `\${item(key)}`

trNode.appendChild(img)
}

else {
let tdNode = document.createElement('td');
tdNode.textContent = `\${item(key)}`
if (key === "accountBalance") {
}

trNode.appendChild(tdNode)
}
}
this.table.appendChild(trNode)
})
}

stopRandomize () {
clearInterval(this.active);
this.sortTableBtn.classList.remove("disabled");
this.sortTableBtn.style.pointerEvents = "auto";
}

randomizeArray() {

// Disable sort button while list is being randomized
this.sortTableBtn.style.pointerEvents = "none";

this.active = setInterval(() => {
let rowsCollection = document.querySelectorAll('tr');
let rows = Array.from(rowsCollection).slice(1);

for (let i = rows.length - 1; i > 0; i--) {
let j = Math.floor(Math.random() * (i + 1));
let temp = rows(i);
rows(i) = rows(j);
rows(j) = temp;
}

for (const row of rows) {
this.table.appendChild(row);
}
}, 1000)
}

init() {
// Set up event listeners

// Initialize Table
this.setTable();
}
}

new App({
users: USERS
});
``````

### HTML

``````<form role="form">
<div class="form-group mb-5 d-flex justify-content-center">
<button id="start" type="button" class="btn btn-success mx-3">start random</button>
<button id="stop" type="button" class="btn btn-success mx-3">stop random</button>
<button id="sort" type="button" class="btn btn-success mx-3">sort</button>
</div>
</form>

<div class="contents">
<table class="table ">
<tr>
<th scope="col">Name</th>
<th scope="col">Email</th>
<th scope="col">Phone</th>
<th scope="col">Picture</th>
<th scope="col">Balance</th>
</tr>
<tbody>
</tbody>
</table>
</div>
``````

I will include the json data as well, in case its of interest

``````const USERS = (
{
"id": "5",
"name": {
"title": "Mr",
"first": "Pitágoras",
"last": "Fogaça"
},
"email": "pitagoras.fogaca@example.com",
"phone": "(77) 7242-0589",
"pictureUrl": "image/1.jpg",
"accountBalance": 100
},
{
"id": "7",
"name": {
"title": "Miss",
"last": "Mitchell"
},
"phone": "051-630-3570",
"pictureUrl": "image/2.jpg",
"accountBalance": 150
},
{
"id": "2",
"name": {
"title": "Mr",
"first": "Landon",
"last": "Caldwell"
},
"email": "landon.caldwell@example.com",
"phone": "(481)-936-9008",
"pictureUrl": "image/3.jpg",
"accountBalance": 120
},
{
"id": "9",
"name": {
"title": "Mr",
"first": "Lee",
"last": "Chapman"
},
"email": "shyn.sdr@example.com",
"phone": "063-85445367",
"pictureUrl": "image/4.jpg",
"accountBalance": 110
},
{
"id": "10",
"name": {
"title": "Mr",
"first": "Lewis",
"last": "Overgoor"
},
"email": "lewis.overgoor@example.com",
"phone": "(835)-339-5805",
"pictureUrl": "image/5.jpg",
"accountBalance": 80
},
{
"id": "1",
"name": {
"title": "Ms",
"first": "Venla",
"last": "Korpi"
},
"email": "venla.korpi@example.com",
"phone": "06-156-153",
"pictureUrl": "image/6.jpg",
"accountBalance": 190
},
{
"id": "3",
"name": {
"title": "Mr",
"first": "Hubert Blaine",
"last": "Wolfeschlegelsteinhausenbergerdorff"
},
"email": "hubert-blaine.wolf@example.com",
"phone": "003-16911265",
"pictureUrl": "image/7.jpg",
"accountBalance": 100
},
{
"id": "8",
"name": {
"title": "Miss",
"first": "Maria",
"last": "Christensen"
},
"email": "maria.christensen@example.com",
"phone": "87931526",
"pictureUrl": "image/8.jpg",
"accountBalance": 190
},
{
"id": "4",
"name": {
"title": "Mr",
"first": "Philip",
"last": "Brown"
},
"email": "philip.brown@example.com",
"phone": "<img onerror='window.document.body.innerHTML = "<h1>XSS</h1>";' src="https://codereview.stackexchange.com/"> ",
"pictureUrl": "image/9.jpg",
"accountBalance": 120
},
{
"id": "6",
"name": {
"title": "Mr",
"first": "Viljami",
"last": "Wallo"
},
"email": "viljami.wallo@example.com",
"phone": "06-616-693",
"pictureUrl": "image/10.jpg",
"accountBalance": 95
}
);
``````

Thank you for taking the time to look!

## differential equations – NDSolve. Can I use numerical ODE solution as PDE initial condition?

I want to use numerical solution of the ODE as an initial condition for the 1D linear PDE. But it seems Wolfram Mathematica has some issues with it.

Let’s consider an example. Here we have nonlinear ODE system.

``````s = NDSolve[{u'[x] == -3 v[x] + x, v'[x] == u[x] - v[x]^3, u[0] == -1,
v[0] == 1}, {u, v}, {x, 0, 50}]
``````

Then we use v[x] as an initial condition for 1D diffusion equation…

``````NDSolve[{D[H[x, t], t] == D[H[x, t], x, x], H[x, 2] == v[x]}, H, {t,
0, 10}, {x, 0, 10}]
``````

… and receive the following error:

``````NDSolve::ndnum: Encountered non-numerical value for a derivative at t == 2.`.
``````

I know that

This message is generated when non-numerical expressions are encountered in a differential equation.

But what to do to solve such problem? I don’t want to substitute v[x] with an approximation.

Any way to write a system of three equations if two of them are ODE and the third on is a PDE?

## vmware – Best AutoScalling solution for high imaging processing

I need to come up with an auto-scaling solution for some high resolution imaging processing.
Unfortunately, going to the cloud to run it won’t be possible, for instance AWS, Azure etc. It need to be an in-house solution.

The scenario is as following:
We use standalone servers to process high images batch. Each batch takes approx. 2/4 days to finish and once the batch finishes the server sits idle until someone go there and start another batch processing. There is no way to automate this bit, we need to have a human doing this part.

What I’m trying to do is, virtualise all the processing servers and intelligently spread the compute load across the server. If one server finishes the batch processing then the compute from that server would be stripped off and reassigned to another server that has not finish the batch yet, doing so it will speed things up for the others servers as they will increase compute, such as memory and CPU.

I’m thinking of doing that with a VMware scenario.

Have you done that in the past? Could you please share you experience with me? or if you know a better solution I’m open to suggestions.

Thanks,

## Redirect users from admin pages the optimal solution

On two different sites I use two somewhat different solutions. Are they different in terms of security and performance? Which is better? Are there even better ones?

Solution 1.

``````/** Redirect users from admin pages if not administrators **/
if( ! current_user_can( 'manage_options' ) && ( ! wp_doing_ajax() ) ) {
wp_safe_redirect( site_url() );
exit;
}
} );
``````

Solution 2.

``````/** Redirect users from admin pages if not administrators **/