Minimal polynomial questions

Question: I have to find the minimal polynomial for $\cos(2\pi/5)$ and $\sin(2\pi/5)$ and I'd like to know what is wrong with my attempt:
$\cos(4\pi/5)=\cos(6\pi/5) = 4\cos^3(2\pi/5)-3\cos(2\pi/5)$, that gives $\cos^3(2\pi/5)= (1/4)\cos(4\pi/5)+(3/4)\cos(2\pi/5)$
$\cos^0(2\pi/5)=1$
$\cos(2\pi/5)=\cos(2\pi/5)$
$\cos^2(2\pi/5) =(1/2)\cos(4\pi/5)+(1/2)$
$\cos^3(2\pi/5)=(1/4)\cos(4\pi/5)+(3/4)\cos(2\pi/5)$

$\cos^3(2\pi/5)-(1/2)\cos^2(2\pi/5)-(3/4)\cos(2\pi/5)+(1/4)=0$,
then $\cos(2\pi/5)$ is a root of $t^3-(1/2)t^2-(3/4)t+(1/4)$. But it is not a minimal polynomial. What should I do now? Please, help.
Comment: You could. It is not the only way, there are many.
Comment: The polynomial seems to vanish at $t=1$. Divide by $t-1$ then. We know that $\cos(2\pi/5)$ is not $1$. So, we will not lose that root after that division.
Comment: Thank you so much. How about sin(2pi/5) ? should I do the same steps?
Comment: I know there are many ways to find, but this is my way :) and I would like to know others, Please, post the answer so that I can study more.
Answer: We can try it also this other way:
$$\begin{align}w&=e^{2\pi i/5}=\cos(2\pi/5)+i\sin(2\pi/5)\\w^{-1}&=e^{-2\pi i/5}=\cos(2\pi/5)-i\sin(2\pi/5)\end{align}$$
and $$w^5=e^{2\pi i}=1$$
We need a polynomial that vanishes at $c=\dfrac{w+w^{-1}}{2}=\cos(2\pi/5)$.
Since $0=w^5-1=(w-1)(w^4+w^3+w^2+w+1)$. We know that $w\neq1$ therefore $$w^4+w^3+w^2+w+1=0$$
We do this trick with the equation above
$$0=w^2\left(w^2+w^{-2}+w+w^{-1}+1\right)=w^2\left[\left(w+w^{-1}\right)^2+\left(w+w^{-1}\right)+\frac{1}{2}\right]$$
Therefore $$(2c)^2+2c+\frac{1}{2}=0.$$
Now try to imitate this computation for $s=\dfrac{w-w^{-1}}{2i}=\sin(2\pi/5)$.
I have to leave now, check if I did the computations correct. You can edit the answer yourself, I think.
Comment: Woahh, It's beautiful. I got all but the last step. Do we have to prove the answer is irreducible on Q? How?
Comment: @user73195 In this case we get quadratic polynomials. Proving that they are irreducible can be done just computing their roots and seeing they are not rational.

Minimal polynomial questions


Python Reed-Solomon encoding in a GF(2^8)

Question: I'm working on a school project and I have to encode a message using Reed-Solomon encoding procedure and Python.
I couldn't wrap my head around a way to divide my generator polynomial $g(x)$ with my information polynomial $I(x)x^{n-k}$, and I stumbled upon this implementation (https://rextester.com/ZMBYT68318) :
<code>def RSEncode(self, argMesg, errSize):

        # prepare the generator polynomial
        polyGen = self._rsGenPoly(errSize)

        # prepare the output buffer
        outBuffer = (len(argMesg) + errSize)
        outBuffer = [0] * outBuffer

        # initialise the output buffer
        for mesgPos in range(0, len(argMesg)):
            mesgChar = argMesg[mesgPos]
            outBuffer[mesgPos] = ord(mesgChar)

        # begin encoding
        for mesgPos in range(0, len(argMesg)):
            mesgChar = outBuffer[mesgPos]
            if (mesgChar != 0):
                for polyPos in range(0, len(polyGen)):
                    tempValu = self.__gfMult(polyGen[polyPos], mesgChar)
                    outBuffer[mesgPos + polyPos] ^= tempValu

        # finalise the output buffer
        for mesgPos in range(0, len(argMesg)):
            mesgChar = argMesg[mesgPos]
            outBuffer[mesgPos] = ord(mesgChar)

        # return the output buffer
        return (outBuffer)

</code>
What I can't understand is why a multiplication is working when I kept reading that I had to divide $I(x)x^{n-k}$, my information offset by $n-k$ parity bits, with $g(x)$ my generator polynomial so that my final encoded message would be
$$
E(x) = I(x)x^{n-k} + r(x)
$$
$r(x)$ being the remainder of my euclidean division.
I know that in a Galois field, division is multiplication by the inverse modulo p, but it doesn't seem the be the case here, am I missing something ? (Obviously yes !).
Additionnaly, if you have a clue on how to divide two polynomials, I'm definitely good with any advices you may give !
Thanks in advance for the help !
Answer: I finally figured that encoding was actually an implementation of a Synthetic division :
https://en.wikipedia.org/wiki/Synthetic_division
Being new on this website, I also wonder why my post was downvoted without any comment mentioning why, so if anyone can help me understand the reason so I can be a better user of the website, I'm down :) !
Bye !
Comment: I upvoted your answer since you figured it out yourself. The question may have looked code/programming related, but I wouldn't fuss too much about negative votes.


EQ on a pedal specifically Parametric Bandwidth

Question: I am using a software based synth program and have the option to add a Parametric EQ 'pedal' as an effect before console/mixing desk. This Parametric EQ pedal has 3 knobs: | FREQ | GAIN | BANDWIDTH or Q |: I understand the properties of each of these but what I cannot factor for the life of me is specifically to do with the VALUES given in the | BANDWIDTH or Q | area...
I need to know the 'Area Of Effect' or how wide the Q is relative to what specific frequencies it is effecting but the values themselves are just numbers: ranging from 0.10 advancing in increments of 0.01 to a maximum of 12.00
Obviously this would change with the amount of GAIN applied but assuming 0 (zero) GAIN is there an equation to solve this?
If it helps in your answer assume A-440Hz and the lowest and highest frequencies effected by a BANDWIDTH or Q value of 6.00 and 12.00
Thanks
Answer: Bandwidth = Center Frequency / Quality Factor
See the Wikipedia article on Equalization
This means that the higher the Q, the more narrow the boost or cut, and vice-versa.
For your example, with a center at 440 Hz and a Q of 6, the bandwidth would be 73.33 Hz, shrinking to 36.66 Hz for a Q of 12. For context, the G# below A 440 is appoximately 415 Hz, the A# above it is approximately 466 Hz, so the frequency difference between those two notes is wider than the bandwidth of a filter of Q 12 with a center freqeuncy of 440 Hz.
On a personal note, I never use a calculator when I do EQ, I just use my ears.
Comment: In this instance it is vice versa... the smaller value of Q gives less bandwidth (0.10<12.00) the particular reason I ask is to avoid bleed into A# and G#. Specifically, for fabricating the most realistic piano sound I can from a synth. I understand all the parameters involved and just how hard this is but I have done ALOT of work to this end... it's just this particular device/plugin works better than a graphic/visual EQ
Excellent answer though, I'll be able to solve it from here using the numbers you've given I guess I just needed a little 'scope' or light on the issue.
Comment: If the smaller "Q" is giving less bandwidth, then the numbers do not represent the actual quality factor that the letter "Q" normally indicates.


Origin of this generic hockey photo

Question: In my experience, whenever some group, company or organization wants to feature an image of hockey in their print or display media, they use the generic image below that seems to come from an actual game.
I'm very curious about the real origins of this image - where it was taken, who's in it it, etc - and how it became a de-facto image of hockey. Does anyone have any idea?
Comment: The perfect stock photo: action shot, primary colors, no faces, identifying marks, or logos.  It looks like some of the ads on the sidewall have been photoshopped off.
Comment: Why are there 3 close votes on this question for it being too broad? How is asking about a sports photo be too broad?
Comment: @Zack The downside of democracy :)
Comment: I follow hockey very closely and I personally have never seen this photo. As you can tell by the arena size, it's not a professional hockey team. The colors would make me guess a farm team for the Montreal Canadians or a CHL, WHL or QMJHL team with similar jerseys
Comment: If you are watching real hockey, you won't see this image too much as broadcasters and media are licensed to use team trademarks, likeness, etc. However, you see it all over when third party companies want to display hockey but can't legally show trademarked logos.
Comment: @lmray I get your point, but I look at blogs too and have never seen this photo, weird. But away from that point, I'm pretty sure I dug around enough to answer your question! Hope it helps.
Comment: @Zack, feed the image to Google Images and you will get almost a million identical results!
Comment: Google Image results: http://goo.gl/RpkoXz
Comment: It actually looks like a video game.
Answer: I'm almost positive that this team (in red) are the Spokane Chiefs from the WHL. The jerseys match exactly along with the pants. I looked through the leagues of CHL, WHL, QMJHL and AHL and these were the only jerseys that match.
As you can see by the first picture below, the stripes on the jersey match up exactly. If you look in the original photo (with the goalie) you can see a faint blue and white logo on the front of the the other players jersey, this matches the colors of the Cheifs logo.

(source: sportslogos.net)
As you can see from the 2nd photo, the 2 white and 1 red stripe down the leg matches the goalie as well.

As for who the player is? That is hard to figure out. The WHL only keeps roster records back to 1996. After going though all these rosters and looking at goalies who wore the number "1", I came up with this list.

Chris Sharkey

Shane Gris

No Picture

Matt Cockell

No Picture

After further digging, I'm also almost positive that Spokane Chiefs were playing the Portland Winterhawks. I came to this conclusion by looking at the arenas that the teams in the WHL play in. On this certain game, the Chiefs were playing AWAY but wearing their HOME jerseys. Sometimes this happens in hockey (another question to be asked in the future).
The first reason why I came to this conclusion is the look of the arena. If you compare the given picture with the picture below of the Memorial Coliseum, the arena that the Portland Winterhawks play in, you will see many similarities.

You see the red outline that borders the main screen on the jumbotron. You also see the rectangular piece that wraps around the bottom on the jumbotron. Both of these features match the given picture above (although the top of the jumbotron in the given picture is cut off.
You also see the red and white banners that are hanging from the ceiling on the side of the rink. These match the banners in the given picture.
The next similarity that most people would miss is that both arenas have a unique "gap" in their roofs. A gap that extends up that shows exposed scaffolding.
Another similarity that most people would miss is a speaker that is hanging from the roof. If you look in the picture below, the speaker is located between the 3rd and 4th banner to the left of the jumbotron. This speaker is also visible in the picture provided on the left side of the picture in between banners.

Last but not least, the Portland Winterhawks AWAY uniforms are made up of an almost all white jersey and solid black pants, as you can see from the picture below. If you compare this jersey with the one you see of the opposing players in the picture provided, these jerseys match.
Comment: You ought to be a detective! Incredible and very convincing answer!
Comment: You definitely got the stadium right - I found even a better picture, where you can see the whole jumbotron http://www.wallpapergate.com/data/media/360/Hockey_001.jpg
Comment: Haha awesome! I can't believe I tracked that down.

Origin of this generic hockey photo


Angular Universal + Firebase Cloud Function causing memory limit exceeded

Question: Currently I'm working on an Angular 8 application which uses Firebase as backend.
I followed Jeff Delaney's Tutorial and suceeded to deploy on a cloud function called ssr my express server.
Everything works fine... almost ! When the ssr function is deployed, I can see an increase of memory usage of all my cloud functions even the smallest (1 transaction with a get and 1 update in the transaction) :
functions/src/index.ts
// The Cloud Functions for Firebase SDK to create Cloud Functions and setup triggers.
import * as functions from 'firebase-functions';
// The Firebase Admin SDK to access Firestore.
import * as admin from 'firebase-admin';

admin.initializeApp();

export const ssr = functions.https.onRequest(require(`${process.cwd()}/dist/server`).app);

export const unsubscribeToMeal = functions.region('europe-west1').https.onCall((data) => {
  const mealDoc = admin.firestore().doc('meals/' + data.meal.uid);
  const adminDoc = admin.firestore().doc('users/' + data.meal.adminId);
  return admin.firestore().runTransaction(t => {
    return t.get(mealDoc)
      .then(doc => {
        const meal = doc.data();
        if (doc.exists && meal) {
          const promises = [];
          const participantIndex = meal.users.findIndex((element: any) => {
            return element.detail.uid === data.userToUnsubscribe.uid;
          });
          meal.users.splice(participantIndex, 1);
          const pendingRequest = meal.users.filter((user: any) => user.status === 'pending').length > 0;
          const p4 = t.update(mealDoc, { 'users': meal.users, 'participantId': admin.firestore.FieldValue.arrayRemove(data.userToUnsubscribe.uid), 'nbRemainingPlaces': meal['nbRemainingPlaces'] + 1, 'pendingRequest': pendingRequest })
          promises.push(p4);
          if (promises.length > 0) {
            return Promise.all(promises)
              .then(() => console.log('user unsubscribed'))
              .catch((err: any) => console.log('error unsubscribing user : ' + data.userToUnsubscribe.first_name + ' ' + data.userToUnsubscribe.last_name + ' of the meal ' + meal.uid + '. Err : ' + err))
          }
          else {
            // doc.data() will be undefined in this case
            throw new functions.https.HttpsError('not-found', 'no such document!');
          }
        } else {
          // doc.data() will be undefined in this case
          console.log('doc does not exist');
          throw new functions.https.HttpsError('not-found', 'no such document!');
        }
      })
  })
});

Triggering unsubscribeToMeal function goes from 60MB memory usage without the ssr function deployed to 240MB memory usage with.
So I am wondering what is happening ? It looks like the express server app is bootstrap on each cloud function instance which causes an increase of memory use and so more billing.
I limited global variables to minimze cold start as Doug Stevenson explains here, so it shouldn't be that.
server.ts
(global as any).WebSocket = require('ws');
(global as any).XMLHttpRequest = require('xhr2');

import 'zone.js/dist/zone-node';
import 'reflect-metadata';
import { enableProdMode } from '@angular/core';
import * as express from 'express';
import { join } from 'path';

// Faster server renders w/ Prod mode (dev mode never needed)
enableProdMode();

// Express server
export const app = express();
import * as cookieParser from 'cookie-parser';
import { from } from 'rxjs';
app.use(cookieParser());

const PORT = process.env.PORT || 4000;
const DIST_FOLDER = join(process.cwd(), 'dist/browser');

// * NOTE :: leave this as require() since this file is built Dynamically from webpack
const { AppServerModuleNgFactory, LAZY_MODULE_MAP, ngExpressEngine, provideModuleMap } = require('./dist/server/main');

// Our Universal express-engine (found @ https://github.com/angular/universal/tree/master/modules/express-engine)
app.engine('html', ngExpressEngine({
  bootstrap: AppServerModuleNgFactory,
  providers: [
    provideModuleMap(LAZY_MODULE_MAP)
  ]
}));

app.set('view engine', 'html');
app.set('views', DIST_FOLDER);

// Example Express Rest API endpoints
// app.get('/api/**', (req, res) => { });
// Serve static files from /browser
app.get('*.*', express.static(DIST_FOLDER, {
  maxAge: '1y'
}));

// All regular routes use the Universal engine
app.get('*', (req: express.Request, res: express.Response) => {
  res.render('index2', {
    req
  });
});

// Start up the Node server
app.listen(PORT, () => {
  console.log(`Node Express server listening on http://localhost:${PORT}`);
});

Any solution to still have low memory usage (without increasing memory limit of the function) and at the same time ssr function with express server for angular universal ?
Answer: I my opinion it the increase of the memory is nothing unexpected. There is description in your tutorial:

Angular is a client-side framework designed to run apps in the browser. Universal is a tool that can run your Angular app on the server,...

So using SSR solution you are moving running angular app form client to server, so all the code run on normally on client side, now is run on the server. I don't think that it will be possible to run something without reserving resources needed to do it...
Maybe in this particular case AppEngine will be better to deploy it... I hope it will help you somehow :)
Comment: The increase of memory used is of course normal on the server. However, I understood that each function generated a new server instance when they were called and that is why I do not understand why my ssr function impact the memory of my unsubscribeToMeal function.
Answer: After getting in touch with the firebase community: "using firebase deploy --only functions  will redeploy the code for all your functions and the memory used will be cumulative total of all those functions loaded together".
So the solution is to split functions into different files and use process.env.[functionName] with a if statement as explained here to avoid this increase of memory for the expressFunction.
Comment: I was thinking of that, but I didn't manage to find any tutorial... Were you able to use it successfully in your case?
Comment: My answer was to long just for commenting
Answer: Yes vitooh ! You need to split each function into a ts or js file. Here is my new structure:

/functions

/src

index.ts
/my_functs

ssr.ts
unsubscribeToMeal.ts
... other functions

Each function file need to start with exports = module.exports = functions...
For instance, here is the code for my new express function (you can compare to what I had in my first post)
functions/src/my_functs/ssr.ts file
// The Cloud Functions for Firebase SDK to create Cloud Functions and setup triggers.
import * as functions from 'firebase-functions';

exports = module.exports = functions.https.onRequest(require(`${process.cwd()}/dist/server`).app);

Don't forget to import in each file what is needed such as "import * as functions from 'firebase-functions';". I also changed my index.ts file which is used when deploying to firebase with : firebase deploy --only functions and installed glob (npm i glob) from the functions folder.
functions/src/index.ts file

const glob = require("glob");
if (process.env.FUNCTION_NAME) {
  // Specific function requested, find and export only that function
  const functionName = process.env.FUNCTION_NAME;
  const files = glob.sync(`./my_functs/${functionName}.@(js|ts)`, { cwd: __dirname, ignore: './node_modules/**' });
  const file = files[0];
  exports[functionName] = require(file);
} else {
  // Name not specified, export all functions
  const files = glob.sync('./my_functs/*.@(js|ts)', { cwd: __dirname, ignore: './node_modules/**' });
  for (let f = 0, fl = files.length; f < fl; f++) {
    const file = files[f];
    const functionName = file.split('/').pop().slice(0, -3); // Strip off '.(js|ts)'
    exports[functionName] = require(file);
  }
}


Is it possible to left-align the row label in a Row Facet?

Question: Is it possible to left-align the row label in a Row Facet?
In this case the row field of "Sub-Category".
For example, ...
Accessories
Appliances
Art
....................................................................................................................................................................................................
<code>  {
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {
    "values": [
      {
        "Sub-Category": "Accessories",
        "MonthendDate": "2020-01-31T00:00:00",
        "Sales": 2126,
        "Profit": 476
      },
      {
        "Sub-Category": "Accessories",
        "MonthendDate": "2020-02-29T00:00:00",
        "Sales": 2437,
        "Profit": 623
      },
      {
        "Sub-Category": "Accessories",
        "MonthendDate": "2020-03-31T00:00:00",
        "Sales": 3952,
        "Profit": 1192
      },
      {
        "Sub-Category": "Accessories",
        "MonthendDate": "2020-04-30T00:00:00",
        "Sales": 2142,
        "Profit": 358
      },
      {
        "Sub-Category": "Accessories",
        "MonthendDate": "2020-05-31T00:00:00",
        "Sales": 3751,
        "Profit": 1190
      },
      {
        "Sub-Category": "Accessories",
        "MonthendDate": "2020-06-30T00:00:00",
        "Sales": 4849,
        "Profit": 1028
      },
      {
        "Sub-Category": "Accessories",
        "MonthendDate": "2020-07-31T00:00:00",
        "Sales": 7589,
        "Profit": 2403
      },
      {
        "Sub-Category": "Accessories",
        "MonthendDate": "2020-08-31T00:00:00",
        "Sales": 4962,
        "Profit": 1154
      },
      {
        "Sub-Category": "Accessories",
        "MonthendDate": "2020-09-30T00:00:00",
        "Sales": 9727,
        "Profit": 2778
      },
      {
        "Sub-Category": "Accessories",
        "MonthendDate": "2020-10-31T00:00:00",
        "Sales": 5032,
        "Profit": 909
      },
      {
        "Sub-Category": "Accessories",
        "MonthendDate": "2020-11-30T00:00:00",
        "Sales": 8390,
        "Profit": 2181
      },
      {
        "Sub-Category": "Accessories",
        "MonthendDate": "2020-12-31T00:00:00",
        "Sales": 4989,
        "Profit": 1380
      },
      {
        "Sub-Category": "Appliances",
        "MonthendDate": "2020-01-31T00:00:00",
        "Sales": 2548,
        "Profit": 423
      },
      {
        "Sub-Category": "Appliances",
        "MonthendDate": "2020-02-29T00:00:00",
        "Sales": 3521,
        "Profit": 977
      },
      {
        "Sub-Category": "Appliances",
        "MonthendDate": "2020-03-31T00:00:00",
        "Sales": 2474,
        "Profit": 308
      },
      {
        "Sub-Category": "Appliances",
        "MonthendDate": "2020-04-30T00:00:00",
        "Sales": 645,
        "Profit": -144
      },
      {
        "Sub-Category": "Appliances",
        "MonthendDate": "2020-05-31T00:00:00",
        "Sales": 2578,
        "Profit": 692
      },
      {
        "Sub-Category": "Appliances",
        "MonthendDate": "2020-06-30T00:00:00",
        "Sales": 3160,
        "Profit": 897
      },
      {
        "Sub-Category": "Appliances",
        "MonthendDate": "2020-07-31T00:00:00",
        "Sales": 1211,
        "Profit": 197
      },
      {
        "Sub-Category": "Appliances",
        "MonthendDate": "2020-08-31T00:00:00",
        "Sales": 7105,
        "Profit": 1621
      },
      {
        "Sub-Category": "Appliances",
        "MonthendDate": "2020-09-30T00:00:00",
        "Sales": 3088,
        "Profit": 427
      },
      {
        "Sub-Category": "Appliances",
        "MonthendDate": "2020-10-31T00:00:00",
        "Sales": 3336,
        "Profit": 755
      },
      {
        "Sub-Category": "Appliances",
        "MonthendDate": "2020-11-30T00:00:00",
        "Sales": 6746,
        "Profit": 1021
      },
      {
        "Sub-Category": "Appliances",
        "MonthendDate": "2020-12-31T00:00:00",
        "Sales": 6517,
        "Profit": 690
      },
      {
        "Sub-Category": "Art",
        "MonthendDate": "2020-01-31T00:00:00",
        "Sales": 434,
        "Profit": 111
      },
      {
        "Sub-Category": "Art",
        "MonthendDate": "2020-02-29T00:00:00",
        "Sales": 247,
        "Profit": 67
      },
      {
        "Sub-Category": "Art",
        "MonthendDate": "2020-03-31T00:00:00",
        "Sales": 442,
        "Profit": 115
      },
      {
        "Sub-Category": "Art",
        "MonthendDate": "2020-04-30T00:00:00",
        "Sales": 618,
        "Profit": 140
      },
      {
        "Sub-Category": "Art",
        "MonthendDate": "2020-05-31T00:00:00",
        "Sales": 640,
        "Profit": 177
      },
      {
        "Sub-Category": "Art",
        "MonthendDate": "2020-06-30T00:00:00",
        "Sales": 1019,
        "Profit": 262
      },
      {
        "Sub-Category": "Art",
        "MonthendDate": "2020-07-31T00:00:00",
        "Sales": 867,
        "Profit": 251
      },
      {
        "Sub-Category": "Art",
        "MonthendDate": "2020-08-31T00:00:00",
        "Sales": 733,
        "Profit": 199
      },
      {
        "Sub-Category": "Art",
        "MonthendDate": "2020-09-30T00:00:00",
        "Sales": 971,
        "Profit": 267
      },
      {
        "Sub-Category": "Art",
        "MonthendDate": "2020-10-31T00:00:00",
        "Sales": 642,
        "Profit": 123
      },
      {
        "Sub-Category": "Art",
        "MonthendDate": "2020-11-30T00:00:00",
        "Sales": 1387,
        "Profit": 312
      },
      {
        "Sub-Category": "Art",
        "MonthendDate": "2020-12-31T00:00:00",
        "Sales": 862,
        "Profit": 199
      }
    ]
  },
  "spacing": {"row": 2},
  "facet": {
    "row": {
      "field": "Sub-Category",
      "type": "nominal",
        "header": {
        "title": null,
        "labelAngle": 0,
        "labelPadding": 0,
        "titlePadding": -40,
        "labelAlign": "left"
      }
    }
  },
  "spec": {
    "width": 120,
    "height": 20,
    "view": {"stroke": "transparent"},
        "mark": {"type": "area", "interpolate": "natural"},
        "encoding": {
          "x": {
            "field": "MonthendDate",
            "type": "temporal",
            "title": null,
            "timeUnit": "yearmonth",
            "axis": {"format": "%b %y", "orient": "top",
            }
          },
          "y": {
            "field": "Sales",
            "type": "quantitative",
            "aggregate": "sum",
            "scale": {"zero": true},
            "axis": {"title": null, "labels": false, "ticks": false}
          }
        }
      },
  "resolve": {"scale": {"y": "shared"}}
}
</code>
Answer: I think this is currently a bug which you can read more about here: https://github.com/vega/vega-lite/issues/5547. If you edit the Vega spec instead, you can achieve what you want.
Final Image
<code>{
  "$schema": "https://vega.github.io/schema/vega/v5.json",
  "background": "white",
  "padding": 5,
  "data": [
    {
      "name": "source_0",
      "values": [
        {
          "Sub-Category": "Accessories",
          "MonthendDate": "2020-01-31T00:00:00",
          "Sales": 2126,
          "Profit": 476
        },
        {
          "Sub-Category": "Accessories",
          "MonthendDate": "2020-02-29T00:00:00",
          "Sales": 2437,
          "Profit": 623
        },
        {
          "Sub-Category": "Accessories",
          "MonthendDate": "2020-03-31T00:00:00",
          "Sales": 3952,
          "Profit": 1192
        },
        {
          "Sub-Category": "Accessories",
          "MonthendDate": "2020-04-30T00:00:00",
          "Sales": 2142,
          "Profit": 358
        },
        {
          "Sub-Category": "Accessories",
          "MonthendDate": "2020-05-31T00:00:00",
          "Sales": 3751,
          "Profit": 1190
        },
        {
          "Sub-Category": "Accessories",
          "MonthendDate": "2020-06-30T00:00:00",
          "Sales": 4849,
          "Profit": 1028
        },
        {
          "Sub-Category": "Accessories",
          "MonthendDate": "2020-07-31T00:00:00",
          "Sales": 7589,
          "Profit": 2403
        },
        {
          "Sub-Category": "Accessories",
          "MonthendDate": "2020-08-31T00:00:00",
          "Sales": 4962,
          "Profit": 1154
        },
        {
          "Sub-Category": "Accessories",
          "MonthendDate": "2020-09-30T00:00:00",
          "Sales": 9727,
          "Profit": 2778
        },
        {
          "Sub-Category": "Accessories",
          "MonthendDate": "2020-10-31T00:00:00",
          "Sales": 5032,
          "Profit": 909
        },
        {
          "Sub-Category": "Accessories",
          "MonthendDate": "2020-11-30T00:00:00",
          "Sales": 8390,
          "Profit": 2181
        },
        {
          "Sub-Category": "Accessories",
          "MonthendDate": "2020-12-31T00:00:00",
          "Sales": 4989,
          "Profit": 1380
        },
        {
          "Sub-Category": "Appliances",
          "MonthendDate": "2020-01-31T00:00:00",
          "Sales": 2548,
          "Profit": 423
        },
        {
          "Sub-Category": "Appliances",
          "MonthendDate": "2020-02-29T00:00:00",
          "Sales": 3521,
          "Profit": 977
        },
        {
          "Sub-Category": "Appliances",
          "MonthendDate": "2020-03-31T00:00:00",
          "Sales": 2474,
          "Profit": 308
        },
        {
          "Sub-Category": "Appliances",
          "MonthendDate": "2020-04-30T00:00:00",
          "Sales": 645,
          "Profit": -144
        },
        {
          "Sub-Category": "Appliances",
          "MonthendDate": "2020-05-31T00:00:00",
          "Sales": 2578,
          "Profit": 692
        },
        {
          "Sub-Category": "Appliances",
          "MonthendDate": "2020-06-30T00:00:00",
          "Sales": 3160,
          "Profit": 897
        },
        {
          "Sub-Category": "Appliances",
          "MonthendDate": "2020-07-31T00:00:00",
          "Sales": 1211,
          "Profit": 197
        },
        {
          "Sub-Category": "Appliances",
          "MonthendDate": "2020-08-31T00:00:00",
          "Sales": 7105,
          "Profit": 1621
        },
        {
          "Sub-Category": "Appliances",
          "MonthendDate": "2020-09-30T00:00:00",
          "Sales": 3088,
          "Profit": 427
        },
        {
          "Sub-Category": "Appliances",
          "MonthendDate": "2020-10-31T00:00:00",
          "Sales": 3336,
          "Profit": 755
        },
        {
          "Sub-Category": "Appliances",
          "MonthendDate": "2020-11-30T00:00:00",
          "Sales": 6746,
          "Profit": 1021
        },
        {
          "Sub-Category": "Appliances",
          "MonthendDate": "2020-12-31T00:00:00",
          "Sales": 6517,
          "Profit": 690
        },
        {
          "Sub-Category": "Art",
          "MonthendDate": "2020-01-31T00:00:00",
          "Sales": 434,
          "Profit": 111
        },
        {
          "Sub-Category": "Art",
          "MonthendDate": "2020-02-29T00:00:00",
          "Sales": 247,
          "Profit": 67
        },
        {
          "Sub-Category": "Art",
          "MonthendDate": "2020-03-31T00:00:00",
          "Sales": 442,
          "Profit": 115
        },
        {
          "Sub-Category": "Art",
          "MonthendDate": "2020-04-30T00:00:00",
          "Sales": 618,
          "Profit": 140
        },
        {
          "Sub-Category": "Art",
          "MonthendDate": "2020-05-31T00:00:00",
          "Sales": 640,
          "Profit": 177
        },
        {
          "Sub-Category": "Art",
          "MonthendDate": "2020-06-30T00:00:00",
          "Sales": 1019,
          "Profit": 262
        },
        {
          "Sub-Category": "Art",
          "MonthendDate": "2020-07-31T00:00:00",
          "Sales": 867,
          "Profit": 251
        },
        {
          "Sub-Category": "Art",
          "MonthendDate": "2020-08-31T00:00:00",
          "Sales": 733,
          "Profit": 199
        },
        {
          "Sub-Category": "Art",
          "MonthendDate": "2020-09-30T00:00:00",
          "Sales": 971,
          "Profit": 267
        },
        {
          "Sub-Category": "Art",
          "MonthendDate": "2020-10-31T00:00:00",
          "Sales": 642,
          "Profit": 123
        },
        {
          "Sub-Category": "Art",
          "MonthendDate": "2020-11-30T00:00:00",
          "Sales": 1387,
          "Profit": 312
        },
        {
          "Sub-Category": "Art",
          "MonthendDate": "2020-12-31T00:00:00",
          "Sales": 862,
          "Profit": 199
        }
      ]
    },
    {
      "name": "data_0",
      "source": "source_0",
      "transform": [
        {
          "type": "formula",
          "expr": "toDate(datum[\"MonthendDate\"])",
          "as": "MonthendDate"
        },
        {
          "field": "MonthendDate",
          "type": "timeunit",
          "units": ["year", "month"],
          "as": ["yearmonth_MonthendDate", "yearmonth_MonthendDate_end"]
        },
        {
          "type": "aggregate",
          "groupby": ["yearmonth_MonthendDate", "Sub-Category"],
          "ops": ["sum"],
          "fields": ["Sales"],
          "as": ["sum_Sales"]
        }
      ]
    },
    {
      "name": "row_domain",
      "source": "data_0",
      "transform": [{"type": "aggregate", "groupby": ["Sub-Category"]}]
    }
  ],
  "signals": [
    {"name": "child_width", "value": 120},
    {"name": "child_height", "value": 20}
  ],
  "layout": {
    "padding": {"row": 2, "column": 20},
    "columns": 1,
    "bounds": "full",
    "align": "all"
  },
  "marks": [
    {
      "name": "row_header",
      "type": "group",
      "role": "row-header",
      "from": {"data": "row_domain"},
      "sort": {"field": "datum[\"Sub-Category\"]", "order": "ascending"},
      "title": {
        "text": {
          "signal": "isValid(parent[\"Sub-Category\"]) ? parent[\"Sub-Category\"] : \"\"+parent[\"Sub-Category\"]"
        },
        "orient": "right",
        "style": "guide-label",
        "frame": "group",
        "baseline": "middle",
        "align": "right",
        "angle": 0,
        "offset": -60
      },
      "encode": {"update": {"height": {"signal": "child_height"}}},
      "axes": [
        {
          "scale": "y",
          "orient": "left",
          "grid": false,
          "labels": false,
          "ticks": false,
          "labelOverlap": true,
          "tickCount": {"signal": "ceil(child_height/40)"},
          "zindex": 0
        }
      ]
    },
    {
      "name": "column_header",
      "type": "group",
      "role": "column-header",
      "encode": {"update": {"width": {"signal": "child_width"}}},
      "axes": [
        {
          "scale": "x",
          "orient": "top",
          "grid": false,
          "format": "%b %y",
          "labelFlush": true,
          "labelOverlap": true,
          "tickCount": {"signal": "ceil(child_width/40)"},
          "zindex": 0
        }
      ]
    },
    {
      "name": "cell",
      "type": "group",
      "style": "cell",
      "from": {
        "facet": {
          "name": "facet",
          "data": "data_0",
          "groupby": ["Sub-Category"]
        }
      },
      "sort": {"field": ["datum[\"Sub-Category\"]"], "order": ["ascending"]},
      "encode": {
        "update": {
          "width": {"signal": "child_width"},
          "height": {"signal": "child_height"},
          "stroke": {"value": "transparent"}
        }
      },
      "marks": [
        {
          "name": "child_marks",
          "type": "area",
          "style": ["area"],
          "sort": {"field": "datum[\"yearmonth_MonthendDate\"]"},
          "from": {"data": "facet"},
          "encode": {
            "update": {
              "interpolate": {"value": "natural"},
              "orient": {"value": "vertical"},
              "fill": {"value": "#4c78a8"},
              "description": {
                "signal": "\"MonthendDate (year-month): \" + (timeFormat(datum[\"yearmonth_MonthendDate\"], '%b %y')) + \"; Sum of Sales: \" + (format(datum[\"sum_Sales\"], \"\"))"
              },
              "x": {"scale": "x", "field": "yearmonth_MonthendDate"},
              "y": {"scale": "y", "field": "sum_Sales"},
              "y2": {"scale": "y", "value": 0},
              "defined": {
                "signal": "isValid(datum[\"yearmonth_MonthendDate\"]) && isFinite(+datum[\"yearmonth_MonthendDate\"]) && isValid(datum[\"sum_Sales\"]) && isFinite(+datum[\"sum_Sales\"])"
              }
            }
          }
        }
      ],
      "axes": [
        {
          "scale": "x",
          "orient": "top",
          "gridScale": "y",
          "grid": true,
          "tickCount": {"signal": "ceil(child_width/40)"},
          "domain": false,
          "labels": false,
          "aria": false,
          "maxExtent": 0,
          "minExtent": 0,
          "ticks": false,
          "zindex": 0
        },
        {
          "scale": "y",
          "orient": "left",
          "gridScale": "x",
          "grid": true,
          "tickCount": {"signal": "ceil(child_height/40)"},
          "domain": false,
          "labels": false,
          "aria": false,
          "maxExtent": 0,
          "minExtent": 0,
          "ticks": false,
          "zindex": 0
        }
      ]
    }
  ],
  "scales": [
    {
      "name": "x",
      "type": "time",
      "domain": {"data": "data_0", "field": "yearmonth_MonthendDate"},
      "range": [0, {"signal": "child_width"}]
    },
    {
      "name": "y",
      "type": "linear",
      "domain": {"data": "data_0", "field": "sum_Sales"},
      "range": [{"signal": "child_height"}, 0],
      "zero": true,
      "nice": true
    }
  ],
  "config": {"style": {"cell": {"stroke": "transparent"}}}
}
</code>
Comment: Congrats on hitting #2 for [powerbi]
Comment: Thanks horseyride. My dreams of number 1 are likely over though as the site has completely dried up. Did you see this? https://old.reddit.com/r/ChatGPT/comments/15ju114/chatgpt_is_putting_stack_overflow_out_of_business/
Comment: I'm sure you'll make it. So few people upvote their answers though. I'll remember to upvote more of yours when I see them.
Comment: Lol. We'll see. They all deserved votes so they are justified.
Comment: Ha - I see those posts and think "no thank you". There are just so many low effort posts, you can already tell who will engage and show the minimum amount of gratitude.


AppCompatActivity as a dialog without title

Question: I have an Activity inherited from AppCompactActivity. in manifest for activity set theme:

When I run activity, it shows as a dialog, but title is shown! i try supportRequestWindowFeature(Window.FEATURE_NO_TITLE) and  RequestWindowFeature(Window.FEATURE_NO_TITLE) but title still displayed. Please let me know, What is wrong?

Edit
I solve it, only change android:windowNoTitle to  windowNoTitle! because i am use AppCompactActvity!
Comment: Add your edit as an answer and accept it, I nearly missed this in the edit :)
Comment: supportRequestWindowFeature(Window.FEATURE_NO_TITLE) working for me. When this is first sattement in activity's onCreate() method
Comment: @Harsh I think your answer is the right solution.
Comment: This is happening for me too. It remains even when I add a toolbar as the action bar. Seems like some kind of bug to me. You can set the title string as an empty string, but it's still there, so it affects the centering.
Answer: If you are having AppCompatActivity then the following won't work
requestWindowFeature(Window.FEATURE_NO_TITLE);
The simple way is to set it in the style.xml file.

It is name="windowNoTitle", not name="android:windowNoTitle"

If you want to remove it programmatically then add the following in onCreate()
getSupportActionBar().hide();

Comment: Careful, it is "windowNoTitle" not "android:windowNoTitle"
Comment: < It is name="windowNoTitle", not name="android:windowNoTitle" >
Thanks bro
Answer: AppCompatActivity is different than Activity and has its own features. For the same purpose, you can simply use -
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);

You can look up the documentation here
Note: Add this before setContentView() to avoid crash.
Answer: Set below style in your style.xml

then set this theme in your activity
<activity
    android:name=".yourDailogActivity"
    android:configChanges="orientation"
    **android:theme="@style/customDialogTheme"**
    android:screenOrientation="portrait" />

Answer: Should keep nothing over Activity title. if following these steps activity title will be hidden.
style.xml:
    </style>

manifiest.xml:
 <activity
            android:name="YouActivity"
            android:theme="@style/MyTitledActivityDialogTheme" />

YourClass.java:
after setContentView(R.layout.xyz) like this
  setContentView(R.layout.xyz);
  if (getSupportActionBar() != null)
      getSupportActionBar().hide();

Answer: please use the request window feature before setContentView() as below
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);

Answer: Should keep nothing over <string name="app_name"></string>.so when you run your activity it will show dialog with "NO Title".
string.xml:
         <resources>
               <string name="app_name"></string>
               <string name="hello_world">Hello world!</string>
               <string name="action_settings">Settings</string>
        </resources>

Comment: Afaik the default title is the activity's label (which often refers to app_name), but it is not a good solution to just use an empty string as activity label.


Pyarrow error: while running a pandas udf in pyspark

Question: I am using AWS EMR (5.29) to run a pyspark job but receiving this error when I apply a pandas udf.
pyarrow.lib.ArrowInvalid: Input object was not a NumPy array
Here's the dummy code to replicate the issue.
import pyspark.sql.functions as F
from pyspark.sql.types import *

df = spark.createDataFrame([
    (1, "A", "X1"),
    (2, "B", "X2"),
    (3, "B", "X3"),
    (1, "B", "X3"),
    (2, "C", "X2"),
    (3, "C", "X2"),
    (1, "C", "X1"),
    (1, "B", "X1"),
], ["id", "type", "code"])

and here's the dummy udf
schema = StructType([
    StructField("code", StringType()),
])

@F.pandas_udf(schema, F.PandasUDFType.GROUPED_MAP)
def dummy_udaf(pdf):
    pdf = pdf[['code']]
    return pdf

and when I run this line,
df.groupby('type').apply(dummy_udaf).show()

I am receiving this error:
An error occurred while calling o149.showString.
: org.apache.spark.SparkException: Job aborted due to stage failure: Task 64 in stage 12.0 failed 4 times, most recent failure: Lost task 64.3 in stage 12.0 (TID 66, ip-10-161-108-245.vpc.internal, executor 2): org.apache.spark.api.python.PythonException: Traceback (most recent call last):
  File "/mnt2/yarn/usercache/livy/appcache/application_1585015669438_0003/container_1585015669438_0003_01_000253/pyspark.zip/pyspark/worker.py", line 377, in main
    process()
  File "/mnt2/yarn/usercache/livy/appcache/application_1585015669438_0003/container_1585015669438_0003_01_000253/pyspark.zip/pyspark/worker.py", line 372, in process
    serializer.dump_stream(func(split_index, iterator), outfile)
  File "/mnt2/yarn/usercache/livy/appcache/application_1585015669438_0003/container_1585015669438_0003_01_000253/pyspark.zip/pyspark/serializers.py", line 287, in dump_stream
    batch = _create_batch(series, self._timezone)
  File "/mnt2/yarn/usercache/livy/appcache/application_1585015669438_0003/container_1585015669438_0003_01_000253/pyspark.zip/pyspark/serializers.py", line 256, in _create_batch
    arrs = [create_array(s, t) for s, t in series]
  File "/mnt2/yarn/usercache/livy/appcache/application_1585015669438_0003/container_1585015669438_0003_01_000253/pyspark.zip/pyspark/serializers.py", line 256, in <listcomp>
    arrs = [create_array(s, t) for s, t in series]
  File "/mnt2/yarn/usercache/livy/appcache/application_1585015669438_0003/container_1585015669438_0003_01_000253/pyspark.zip/pyspark/serializers.py", line 254, in create_array
    return pa.Array.from_pandas(s, mask=mask, type=t, safe=False)
  File "pyarrow/array.pxi", line 755, in pyarrow.lib.Array.from_pandas
  File "pyarrow/array.pxi", line 265, in pyarrow.lib.array
  File "pyarrow/array.pxi", line 80, in pyarrow.lib._ndarray_to_array
  File "pyarrow/error.pxi", line 84, in pyarrow.lib.check_status
pyarrow.lib.ArrowInvalid: Input object was not a NumPy array

Tried to use downgraded version of arrow as suggested here and also disabled pyarrow optimization as suggested here, but nothing worked.
Comment: this works fine on my local setup. I've pyarrow 0.13.0 installed. Also, I've pandas 0.22.0 and numpy 1.17.4
Comment: Hey @Bitswazsky yeah, works fine for me too on local. This is happening only on AWS EMR. Not sure why.
Answer: I had the same problem as you (on AWS EMR) and was able to resolve it by installing pyarrow==0.14.1. I don't know exactly why it didn't work for you, but one guess is that you needed to perform this installation in a bootstrap script so that it occurred on all machines in your cluster. It won't be enough to just set the environment variable in the notebook you are working in. Hope this helps you!
Comment: yeah, It didn't work for me because I had another packages in bootstrap script, I guess, one of those packages where upgrading the pyarrow again.

But, when I removed all pip dependencies & just added `pyarrow==0.14.1` to boostrap script, it worked. Thanks for answering, I was going to answer it myself actually.


Only a view filters in exposed filter block

Question: I have a view with 7 exposed filters in an exposed filters block.
But I only want to have 2 filters in the exposed form block. All 7 filters I want to have on the views page.
Is there another solution then display: none?
Answer: You could copy the view for your second use case and only make the 2 needed filters exposed and expose that as a block.
Answer:
Create a new page display, this will copy all the fields and filters from the 'master' display.
Click on the filter you want to remove from the block display.
Select "This block (override)" from the top.
Click remove.

Refer the screenshot:

NOTE: I took the snapshot for the filter "This page (override)". In your case please make sure you select "This block (override) instead.
Comment: Thanks for the answers. But what I forgot to write:

When applying the exposed filter I redirect to the views page. Means: for example the filter is placed on frontpage and when applying it the user will be redirected to the path of the view.

This is because there's no space for the view results.


Using a Normal Button (Non-Radio/Checkbox), how can I ensure only one value is chosen AND deselects another if one is chosen?

Question: This is a very cut-down version to visualize what I'd like to do.
My HTML

Please select a number.

   <button class="rating">1</button>
   <button class="rating">2</button>
   <button class="rating">3</button>
   <button class="rating">4</button>
   <button class="rating">5</button>

My JS
let allBtns = document.querySelectorAll(".rating");

allBtns.forEach((option) => {
  option.addEventListener("click", function () {
    option.style.backgroundColor = "orange";
  });
});

Essentially, I want a user to be able to click on only a single rating (1 thru 5) that will eventually be used to update a string.
The main problem I'd like to tackle right now is being able to select one value, pick another one, and have the previously chosen value be deselected. I was able to find a method using radios, and checkboxes will work,  but I also want to keep the button style because that's how it's supposed to be displayed.
Is this possible with a normal button element?
Comment: are you using something like react or vue?
Comment: @Mulan No, I just started using js like a couple weeks ago.
Answer:

let allBtns = document.querySelectorAll(".rating");

allBtns.forEach((option) => {
  option.addEventListener("click", function (event) {
    allBtns.forEach(el => {
      el.classList.remove('active');
    });

    event.currentTarget.classList.add('active');
  });
});
.rating.active {
  background-color: orange;
}

Please select a number.

 <button role="radio" class="rating">1</button>
 <button role="radio" class="rating">2</button>
 <button role="radio" class="rating">3</button>
 <button role="radio" class="rating">4</button>
 <button role="radio" class="rating">5</button>

Identifies the currently selected button element with .active
When the button is selected, remove the .active from all Button Elements and insert the .active into the newly selected button.
Comment: Due to my JS inexperience, I neglected that every time the button is clicked on, the innerText value is captured automatically due to how I declared/initialized the variable. Please ignore my last question.
Comment: With this answer, would I be able to check if it has the "active" class to store the value and then update a string?
Comment: I don't quite understand the question. Do you want to get the value of a button with class "active"?
Answer: You should memoize last button, then change it back on next click, like this:

let allBtns = document.querySelectorAll(".rating");
let lastBtn;

allBtns.forEach((option) => {
  option.addEventListener("click", function () {
    lastBtn && (lastBtn.style.backgroundColor = null);
    (lastBtn = option).style.backgroundColor = "orange";
  });
});

Please select a number.

   <button class="rating">1</button>
   <button class="rating">2</button>
   <button class="rating">3</button>
   <button class="rating">4</button>
   <button class="rating">5</button>

Comment: How does this code work exactly? I don't quite understand the semantics, but this is the answer that solves my problem.
Comment: @Marcus Can you specify what part you did not understood, to help me be more succinct with an answer?
Comment: I apologize. More specifically, how does the "lastBtn && (lastBtn.style..)" and "(lastBtn = option). work exactly? Are these conditional statements?
Comment: That first statement is a ["short-circuited"](https://en.wikipedia.org/wiki/Short-circuit_evaluation) conjunction operator, the second is just an assignment operation, both are using [grouping operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Grouping).


Tampura vs 4-4 Tabla Playing during Bansuri Practice

Question: So far, I thought one should play Tampura when practicing Bansuri. The Tampura must be on Pa and on the same scale as the Bansuri.
Now this video says we must use 4-4 Tabla (which, of course can be downloaded as an app)
But I am really confused.
When do we play Tampura in the background, and when do we play 4-4 Tabla in the background?
Further Info
The following video introduces Rhythm. As soon as he says turn on 4-4 Tabla I get lost
Please clarify my above questions
Answer: Tanpura plays the base shruti continuously in the background (with Sa, bottom Sa, and Pa). This develops the reference for the rest of the notes. If you change the Tanpura settings, the same set of fingering can surprisingly bring the feeling of an entirely different raga!
On the other hand, Tabla provides the rhythm. Tabla is also tuned to the shruti provided by Tanpura, for which, one setting is provided in the electronic and software Tabla. The shruti of a physical (actual) Tabla is adjusted by delicately adjusting the tensions on its leather strings on the sides.
In the very beginning, it's easy to add the Tanpura, as it only plays itself, filling up the musical space with a soothing background. When it's time to use the rhythm, Tabla can be added.


Issues accessing neo4j data with spring data

Question: Is it possible to have full access to my neo4j graph with spring framework if I haven't build the graph with using spring? I am trying some examples and it seems that it's not working properly as some metadata that spring creates don't exists.
EDIT:
For example I have this error No primary SDN label exists .. (i.e one starting with _) when I am trying to access a node by it's id i.e. nodeRepository.findOne(new Long(157138))
Comment: I've used neo4j a lot, but I'm new to spring-data-neo4j.  I observe that there's a fair amount of class magic going on in the background, where certain Java classes get mapped to certain labels in the DB.  According to the class inheritance hierarchy, it seems in our spring-data-neo4j DBs that many nodes will get many labels (corresponding to intermediate classes).
Comment: Let's see if you get an answer, I'm interested too - from the limited bit of how I've seen it work, I'm guessing you'll need to transform your data into a set of labels that spring-data-neo4j would recognize as being bound to a particular set of objects before it's going to work, but hopefully I'm wrong.
Answer: Use template.postEntityCreation(node/rel, DomainEntity.class) to add the metadata or look into Spring Data Neo4j 4 which also works with your existing graph out of the box.
Comment: postEntityCreation is Deprecated. Is there another solution maybe?


Tela não se ajusta

Question: Estou usando Wordpress. No computador, a página a seguir: http://jqnews.gq/quadro-de-horarios/ , mostra todas as tabelas da maneira correta.
Já no celular e aparelhos com telas menores, as tabelas ficam incompletas. Pela metade, ou coisa parecida.
IMAGENS:
Comment: Mas esta tabela é o que **html**?
Comment: Fica "cortando" simplesmente pq a tabela não cabe na tela por ser grande de mais. Além disso em algum lugar do seu código deve ter um overflow:hidden, que não deixa rolar a página na horizontal para ver a tabela toda
Comment: Ja tive problemas nesse sentido e a solução é colocar um overflow na horizontal. Nao tem como voce exibir uma tabela deste tamanho em uma tela menor. ou voce criar com div quando o dispositivo estiver em um determinado tamanho
Answer: Sua div id="primary" ta float right isso joga todos os elementos dela para direita.
Usa div com width mas com % ex 70% e os elementos maiores, tipo o horário do primeiro ano, você coloca em outra div, vai separando assim.
Comment: Como eu faço isso no wordpress?
Comment: Você criou esse tema ou você está usando algo pronto do wordpress?
Comment: Estou usando um tema
Comment: Infelizmente não consigo te ajudar nesse caso, você precisaria entrar na parte de programação do código para poder fazer essas alterações.

Tela não se ajusta


Can't sign in with Firebase Facebook sign In

Question: I'm using Ionic2 and I'm trying to make Firebase Facebook Sign In work.
When I click on Facebook Sign In button inside my App I get this error:

These are my Facebook App settings:
Comment: Can you post the Ionic code where you're making the call to Facebook. The config part.
Answer: You are Using wrong oAuth redirect URIs, It should be like this
<code>https://auth.firebase.com/v2/your-app-name-in-firebase/auth/facebook/callback
</code>


A question on a countable discrete closed set

Question: Let $X$ be a topological group and let $D$ is a countable discrete closed subset of $X$. We also let $ \mathcal U= \{U_d: d\in D\}$ of open sets of $X$ such that witnesses that $D$ is closed discrete, i.e., for every $d \in D$, $U_d \cap D=\{d\}$.

Is there a family $\mathcal W= \{W_d: d\in D\}$  of open sets of $X$ such that (1) $W_d\cap D=\{d\}$ for each $d\in D$; (2) $\overline{\bigcup W} \subset \bigcup \mathcal U$?

Thanks ahead.
Comment: I apologize for my initial answer, it's trickier than I thought! I'll think about it more carefully.
Comment: Okay. Thank you still:)
Comment: I'm trying to prove the stronger result: there is a basis of closed neighborhoods of $D$. Seems true to me but I can't prove it...
Comment: Alex's answer is right, but it's not obvious that there is a pseudocompact group that isn't countably compact. You'll find one in [this paper](http://www.ams.org/journals/proc/1962-013-01/S0002-9939-1962-0133392-8/); it's the group $K$ whose description begins at the bottom of p. $38$.
Answer: It seems the following.
:-) At the first sight this question is not related to my speciality. But at the second... Let $G$ be a pseudocompact topological group which is not countably compact. I leave to you the pleasure to do the rest.


Sylvester's equation with Hadamard product

Question: So I've been struggling with this problem for a very, very long time. For $W, Y \in \mathbb{R}^{T \times N}, U \in \mathbb{R}^{N \times K}$ and $R\in \mathbb{R}^{T \times T}$, find $V \in \mathbb{R}^{T \times K}$ such that
$$
W \circ (V U^T)U + V + R^T R V = C
$$
where $\circ$ is the Hadamard (or element-wise) product. I know that in the absence of $W$ this would be Sylvesters's equation and thus (under condition ...) be solvable by
$$
vec(V) = (I_K \otimes R^T R + (U^T U + I_K) \otimes  I_T)^{-1}vec(C)
$$
where $\otimes$ is the Kronecker-product. Does anyone know how to solve this when the Hadamard-product $W \circ \dots$ is inserted into the mix?
EDIT: The solution posed by Omnomnomnom was very good and with a minor fix turned out to solve my problem. For future reference I post the full solution. We first need to vectorize the equation
$$
\begin{align}
\text{vec}\left[W \circ (V U^T)U + V + R^T R V \right] = \text{vec}[C] \\
\text{vec}\left[W \circ (V U^T)U\right] + \text{vec}(V) + \text{vec}\left[R^T R V \right] = \text{vec}[C]
\end{align}
$$
If we consider the first term as $\text{vec}\left(A B\right)$ where $A = W \circ (U V^T)$ and $B = U$ we can use that $\text{vec}(A B) = (B^T \otimes I_T)\text{vec}(A)$ to compute
$$
\text{vec}\left[W \circ (VU^T) U\right] = (U^T \otimes I_T)\text{vec}\left[W\circ(VU^T)\right]
$$
Having done this the remaining steps are exactly those of Omnomnomnom's. We compute
$$
\begin{align}
\text{vec}\left[W\circ (VU^T)\right] &= \text{diag}(\text{vec}(W))\text{vec}[VU^T] \\
&= \text{diag}(\text{vec}(W))(U \otimes I_T)\text{vec}(V)
\end{align}
$$
and
$$
\text{vec}(I_K V) = (I_K \otimes I_T)\text{vec}(V)
$$
and
$$
\text{vec}[R^T R V] = (I_K \otimes R^T R) \text{vec}(V)
$$ to arrive at the fully vectorized equation
$$
\left[(U^T \otimes I_T)\text{diag}(\text{vec}(W))(U \otimes I_T) + (I_K \otimes I_T) + (I_K \otimes R^T R) \right]\text{vec}(V) = \text{vec}(C)
$$
which we can guarantee to be solvable if the entries of $W$ are non-negative. Once again thank you Omnomnomnom.
Answer: The trick here is to get a formula for $\operatorname{vec}(W \circ X)$ in terms of $\operatorname{vec}(X)$.  In particular, we have
$$
\operatorname{vec}(W \circ X) = \operatorname{diag}(\operatorname{vec}(W))\operatorname{vec}(X).
$$
With that, we now have
$$
\operatorname{vec}(W \circ (V U^T)U + V + R^T R V) = \\
\operatorname{vec}(W \circ (V U^T)U) +
\operatorname{vec}(V) +
\operatorname{vec}(R^T R V) =\\
\operatorname{diag}(\operatorname{vec}(W))\operatorname{vec}((V U^T)U) +
\operatorname{vec}(V) +
\operatorname{vec}(R^T R V) =\\
\operatorname{diag}(\operatorname{vec}(W))(U^TU \otimes I_T)\operatorname{vec}(V) +
\operatorname{vec}(V) +
(I_K \otimes R^TR)\operatorname{vec}(V) =\\
[\operatorname{diag}(\operatorname{vec}(W))(U^TU \otimes I_T) +
I_K \otimes I_T +
(I_K \otimes R^TR)]\operatorname{vec}(V).
$$
So, we have
$$
[\operatorname{diag}(\operatorname{vec}(W))(U^TU \otimes I_T) +
I_K \otimes I_T +
(I_K \otimes R^TR)]\operatorname{vec}(V) = \operatorname{vec}(C).
$$
When the matrix on the left is invertible, we can say that
$$
\operatorname{vec}(V) = [\operatorname{diag}(\operatorname{vec}(W))(U^TU \otimes I_T) +
I_K \otimes I_T +
(I_K \otimes R^TR)]^{-1} \operatorname{vec}(C).
$$
If you prefer, this can be slightly condensed into
$$
\operatorname{vec}(V) = [\operatorname{diag}(\operatorname{vec}(W))(U^TU \otimes I_T) +
(I_K \otimes (I_T + R^TR))]^{-1} \operatorname{vec}(C).
$$
If the entries of $W$ are non-negative, then we can guarantee that the matrix will be invertible, which is to say that your original equation has a unique solution.


Pacemaker complex resource colocation

Question: I am working on a pacemaker project for our master and slave databases to perform IP based failover.  There will be two IP resources, one for the master, and one for the slave that have to move together.  I realize that what I have marked below is not a complete solution, but the requirements are as follows:

ip_dbmaster can only run on db1 or db21
ip_dbslave can only run on dbslave1 or dbslave2
when ip_dbmaster is on db1, ip_dbslave must be on dbslave1.  When ip_dbmaster is on db2, ip_dbslave must be on dbslave2
before ip_dbmaster and ip_dbslave are run, do some "stuff" (shell scripty stuff, some extended health checks).  Only migrate if "stuff" is successful
same as above, except after the resource migrates

Here is my base configuration:
node $id="75463ec2-702c-427b-965b-b7ffb7814008" db1
node $id="a1f2d612-2d9f-4872-bf24-024f5bece3ce" dbslave2
node $id="d1d42f67-e4f2-4c71-950f-07d94ac01f8d" dbslave1
node $id="f243d865-c1a1-4d52-9100-b0d36a08207c" db2
primitive ip_dbmaster ocf:heartbeat:IPaddr2 \
  params ip="10.153.114.100" cidr_netmask="24"
primitive ip_dbslave ocf:heartbeat:IPaddr2 \
  params ip="10.153.114.101" cidr_netmask="24"
location loc-ip-dbmaster-1 ip_dbmaster \
  rule $id="loc-ip-dbmaster-1-rule" 200: #uname eq db1
location loc-ip-dbmaster-2 ip_dbmaster \
  rule $id="loc-ip-dbmaster-2-rule" 0: #uname eq db2
location loc-ip-dbmaster-3 ip_dbmaster \
  rule $id="loc-ip-dbmaster-3-rule" -inf: #uname eq dbslave2
location loc-ip-dbmaster-4 ip_dbmaster \
  rule $id="loc-ip-dbmaster-4-rule" -inf: #uname eq dbslave1
location loc-ip-dbslave-1 ip_dbslave \
  rule $id="loc-ip-dbslave-1-rule" 200: #uname eq dbslave1
location loc-ip-dbslave-2 ip_dbslave \
  rule $id="loc-ip-dbslave-2-rule" 0: #uname eq dbslave2
location loc-ip-dbslave-3 ip_dbslave \
  rule $id="loc-ip-dbslave-3-rule" -inf: #uname eq db1
location loc-ip-dbslave-4 ip_dbslave \
  rule $id="loc-ip-dbslave-4-rule" -inf: #uname eq db2
property $id="cib-bootstrap-options" \
  dc-version="1.0.8-042548a451fce8400660f6031f4da6f0223dd5dd" \
  cluster-infrastructure="Heartbeat" \
  expected-quorum-votes="2" \
  stonith-enabled="false" \
  symmetric-cluster="false"

So far, #1 and #2 work just great.  #3 seems like it's sort of similar to colocation, but I can't figure out where to start or how to set the dependency.  I see a rules engine, but I haven't quite figured it out yet.  For 4-5, I have no idea if this can be done via pacemaker at all or whether I have to write an external script to handle this piece.
My goal would be able to do this:
crm resource move ip_dbmaster db1

and have everything just go.  I'll settle for
dbfailover db2

...if I have to code some of this external to Pacemaker, or whether this can be built-in.
Thanks for all your help!
Comment: No responses?  What can I do to improve this question?
Comment: still looking for a solution to this ?
Answer: First of all, let me say that I've set up quite a few clusters over the last decade, and I've never seen one where there was a dependency like you've described.  Usually one would set it up so that the services provided don't depend on which host is active and which is standby and you don't care which host has the resource, as long as it's up on one of them.
The only way I can come up with to implement what you want is to implement the slave node as a resource that is initiated by the master node, for example by SSHing over to the slave node to run the IPaddr2 and other resources you need.  Likely using SSH public key authentication with an identity file and authorized_keys entry so that the master can run the commands on the slave without requiring a password.
So this would require creating a "slaveIPaddr2" resource script, that would just wrap a command like:
HOST=`hostname`
exec ssh -i /path/to/ssh-identity dbslave$${HOST#db} /path/to/IPaddr2 "$@"

Then change the ip_dbslave resource to "slaveIPaddr2" instead of "IPaddr2" as the resource to run.
As far as scripts to run before and after migration, these mostly just sound like they would be the normal multiple resource scripts that make up a resource group and precedence using the "group" and "order" configuration items.  For example, creating "master_pre" (the "before" script you want to run on the master), "slave_pre", "master_post", etc... resources, then using "order" to specify that they run in the appropriate order (master_pre, slave_pre, ip_dbmaster, ip_dbslave, master_post, slave_post).  Here you'll also likely need to wrap the slave items with the SSH wrapper, to effectively treat them as a single host as I mentioned above.
It sounds like you want the "pre" script to be run before a migration is even attempted, rather than as a part of starting the resource?  Pacemaker isn't going to migrate a service unless it's told to by you, or the node currently running the service is failing.  In the case of a failing node, your service is down anyway, so no reason to check to try to avoid the migration.  So if you are concerned with preventing the migration when you tell it to migrate, the best answer there may be to make a "migrate" script that runs your pre-service checks, and only goes on with the migration request if the tests succeed.
I don't know of a way in pacemaker to test the other hosts in the cluster before doing a migration, if that is what you are trying to achieve with #4, so it'll likely have to be an external check that enforces that.
Running other resources than just the IPaddr2 is easily done via the "group" and "order" directives.

Pacemaker complex resource colocation


How to handle gridview button click with jQuery?

Question: I have a GridView on my page. This GridView has a template defined as follows:
<code>  <asp:TemplateField HeaderText="EMAIL ADDRESS">
     <ItemTemplate>
        <asp:TextBox ID="txtgvEmailAddress" Text = '<%# Eval("EMAIL")%>' runat="server" Width="300px" />
           <asp:Button ID="btnUpdateEmail" Text = "Update" runat="server" Width="70px" />
     </ItemTemplate>
  </asp:TemplateField>
</code>
How can I handle a click of my txtgvEmailAddress button?
Thank you
Comment: Did you try anything?
Comment: I have the following: $(document).ready(function () {

        $('#btnUpdateEmail').click(function() {
            alert("Clicked");
        });
    });
Answer: jQuery click()
You can also delegate the click with jQuery on()
Answer: Use OnClientClick event of button control.
<code><asp:Button ID="btnUpdateEmail" Text = "Update" runat="server" Width="70px" OnClientClick="Show();" />

    function Show() {
    alert('Clicked');
    return false;
    }
</code>
Comment: I tried to do that but I got an error "Attribute 'ClientIDMode' is not valid"
Comment: @eugene.it, Please remove ClientIdMode from your button control.


Exchange server - Undelivered emails - 421 4.4.2 Connection dropped

Question: we have a problem on our Exchange server 2007.
I have currently 300 undelivered emails to various addresses. I'm getting this error message
421 4.4.2 Connection dropped
I checked the size of attachments and the messages aren't too big (20 KB to 6000 KB).
From 200 mails to various emails addresses 137 weren't delivered.
We don't have any problems with incoming emails, but 20% of outgoing emails just sit in a queue.
Is this a DNS issue ?
Answer: We had a similar issue the same error but not DNS.  It was caused by dropped packets over internet connection (ISP at fault).  We diagnosed by setting up op manager on the public IP interface and the gateway router and see the loss. We then re routed mail to go over ADSL to see if this fixed the issue and it did.  We then went to the ISP and brought it to their attention.
Comment: thanks Johny, it was a problem with our ISP. we had a huge amount of dropped packets.


Saving mp3 through application so that its visible in itunes or music player

Question: How can I save a MP3 file that I have just created in the phone memory so that it is discoverable in the music player of the phone and also visible when connected to itunes?
Is it possible to do so? Or does everything will alwaz b stored in the application sandbox?
Answer: I'm not sure if you'll be able to just add it to the user's music collection programatically. At the very least, you can save it to the Documents directory which the user has access to from iTunes:
<code>NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
</code>
Then you would have to set UIFileSharingEnabled to true in the project's .plist to give the user access to the Documents directory for your app. This setting allows the users to add files to Documents directory as well.
Then they'd have to manually add the files to their collection.
Comment: Thanks A Lot Luke and NSPostWhenIdle. I was unaware of this property called as UIFileSharingEnabled. I hope it solves my issue. I'll do that now.

It also has an alias as "Application supports iTunes file sharing"


How do I add an expression into a query?

Question: When I use the code below, I get the following error:

Call to a member function addExpression() on a non-object

 $query = db_select('node', 'n')
    ->fields('n', array('nid'))
    ->execute()
    ->fetchAssoc();
  $query->addExpression('MAX(nid)', 'max_nid');

What is wrong with that code?
Comment: You added the addExpression after doing the query. It's not correct. You should add before that.
Comment: Where should  I add the addExpression is it before fields() ? I have read that addExpression cannot be chained?
Comment: After fields(). Can you try the code my answer. The format code in the comment block doesn't look good. So i must input in the answer
Answer: Change the code to the following one.
$query = db_select('node', 'n');
$query->fields('n', array('nid'));
$query->addExpression('MAX(nid)', 'max_nid');
$query->execute()->fetchAssoc();

The value returned from fetchAssoc() is an array. Since you are assigning the value returned from fetchAssoc() to $query, and then calling $query->addExpression(), you rightly get the error. You cannot call a method on something that is not an object (in this case, an array).
If you want to list all the node IDs and set max_nid to the maximum value, you can use the following code.
$query = db_select('node', 'n');
$query->fields('n', array('nid','type'));
$query->leftJoin('node', 'n1', 'n1.type = n.type');
$query->addExpression('MAX(n1.nid)', 'max_nid');
$query->groupBy('n.nid');
$result = $query->execute()->fetchAll();

Comment: I got the following error while trying to use the above code.Call to a member function execute() on a non-object
Comment: Please try again
Comment: Sorry now its working but i am not able to get the value for MAX(nid).Do we need to write something else to get the value
Comment: Please check the update of my answer
Comment: So I would have to write $query->execute()->fetchAssoc(); only at the variable where I need get the data..
Comment: Can you tell me what is your purpose for that SQL sentence?
Comment: Why am I getting a single value when database table contains multiple values for nids ??
Comment: I want to get the all the list of nids and along with that I want to get the max_nid  which are of a specific type ?
Comment: Got it by using fetchAll() i could get the list of all nids..
Comment: Yes you can use the fetchAll. Please check my update in answer for further information. I think it will help.
Comment: The updated answer worked for me.


Adding a volume to a Kubernetes StatefulSet using kubectl patch

Question: Problem summary:
I am following the Kubernetes guide to set up a sample Cassandra cluster. The cluster is up and running, and I would like to add a second volume to each node in order to try enable backups for Cassandra that would be stored on a separate volume.
My attempt to a solution:
I tried editing my cassandra-statefulset.yaml file by adding a new volumeMounts and volumeClaimTemplates entry, and reapplying it, but got the following error message:
$ kubectl apply -f cassandra-statefulset.yaml
storageclass.storage.k8s.io/fast unchanged
The StatefulSet "cassandra" is invalid: spec: Forbidden: updates to statefulset spec for fields other than 'replicas', 'template', and 'updateStrategy' are forbidden

I then tried to enable rolling updates and patch my configuration following the documentation here:
https://kubernetes.io/docs/tasks/run-application/update-api-object-kubectl-patch/
$ kubectl patch statefulset cassandra -p '{"spec":{"updateStrategy":{"type":"RollingUpdate"}}}'
statefulset.apps/cassandra patched (no change)

My cassandra-backup-patch.yaml:
spec:
  template:
    spec:
      containers:
        volumeMounts:
        - name: cassandra-backup
          mountPath: /cassandra_backup
  volumeClaimTemplates:
  - metadata:
      name: cassandra-backup
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: fast
      resources:
        requests:
          storage: 1Gi

However this resulted in the following error:
$ kubectl patch statefulset cassandra --patch "$(cat cassandra-backup-patch.yaml)"
The request is invalid: patch: Invalid value: "map[spec:map[template:map[spec:map[containers:map[volumeMounts:[map[mountPath:/cassandra_backup name:cassandra-backup]]]]] volumeClaimTemplates:[map[metadata:map[name:cassandra-backup] spec:map[accessModes:[ReadWriteOnce] resources:map[requests:map[storage:1Gi]] storageClassName:fast]]]]]": cannot restore slice from map

Could anyone please point me to the correct way of adding an additional volume for each node or explain why the patch does not work? This is my first time using Kubernetes so my approach may be completely wrong. Any comment or help is very welcome, thanks in advance.
Answer: The answer is in your first log:
The StatefulSet "cassandra" is invalid: spec: Forbidden: updates to statefulset spec for fields other than 'replicas', 'template', and 'updateStrategy'

You can't change some fields in a statefulset after creation. You will likely need to delete and recreate the statefulset to add a new volumeClaimTemplate.
edit:
It can many times be useful to leave your pods running even when you delete the statefulset. To accomplish this use the --cascade=false flag on the delete operation.
kubectl delete statefulset <name> --cascade=false

Then your workload will stay running while you recreate your statefulset with the updated VPC.
Comment: This really saved me some serious headaches, thanks.
Also, looks like the `--cascade=false` argument is deprecated in favour of `-cascade=orphan`.
Answer: As mentioned by switchboard.op, deleting is the answer.
but
Watch out for deleting these objects:

PersistentVolumeClaim (kubectl get pvc)
PersistentVolume (kubectl get pv)

which for example in case you'd want to do just helm uninstall instead of kubectl delete statefulset/<item> will be deleted thus unless there's any other reference for the volumes and in case you don't have backups of the previous YAMLs that contain the IDs (i.e. not just generated from Helm templates, but from the orchestrator) you might have a painful day ahead of you.
PVCs and PVs hold IDs and other reference properties for the underlying (probably/mostly?) vendor specific volume referencing by e.g. S3 or other object or file storage implementation used in the background as a volume in a Pod or other resources.
Deleting or otherwise modifying a StatefulSet if you preserve the PVC name within the spec doesn't affect mounting of the correct resource.
If in doubt, always just copy locally the whole volume prior to doing destructive action to PVCs and PVs if you need them in the future or running commands without knowing the underlying source code e.g. by:
kubectl cp <some-namespace>/<some-pod>:/var/lib/something /tmp/backup-something

and then just load it back by reversing the arguments.
Also for Helm usage, delete the StatefulSet, then issue helm upgrade command and it'll fix the missing StatefulSet without touching PVCs and PVs.


System Differential Equation - problem

Question: i have a difficulty in this problem.Help me please.
Let the differential system order $n$ : $$ \dfrac{d X}{dt}=f(X)$$
with $X=(x_1,x_2,...,x_n)$.
Prove that if we denote $\tau=t_2-t_1,$ then for any solution $X$ for this system satisfying $X(t_1)=X(t_2)$, we have $$X(t+\tau)=X(t)$$.
Let $K$ the set of real numbers $\tau$ such as $X(t+\tau)=X(t)$ holds.
2- Prouve that $K$ is additive group.
3- Puove that, if $K$ does not admit a minimum greater than 0, the solution is constant.
4- Deduce that the solution of this system have 3 possibilities: peridic, not periodic or probably constant.
Answer: So, in plain words, you want to show that:

If a solution comes full circle after some time $\tau$, it'll repeat the exact same timecourse it followed in the interval $[0,\tau]$;
Any solution repeating itself after time $\tau$ and $\tau'$, will repeat itself after time $\tau+\tau'$;
Either a minimum period exists or else the solution is constant.

For the first two, use the semigroup property.
For the third one, assume a non-constant solution & show that a minimum period exists: first, there exists $t_*>0$ s.t. $X(t_*) \ne X(0)$ (by assumption); second, $\inf_{t}[X(t) = X(t_*)]>0$ (by continuity of the solution); finally, $\tau>t_*>0$ for any period $\tau$ (or else a smaller $t_*$ within $[0,\tau]$ could be found).
NB: I haven't checked, but I've a feeling J. Hale's ODE book might be good reading material for such arguments.

System Differential Equation - problem


Which input range for sampling a Gaussian distribution

Question: I want to sample a 1-dimensional Gaussian, for this I need to generate random numbers in a certain range which will be used as function input.
The function is $$\mathcal{N}(x|0,1) = \frac{1}{(|2 \pi|)^\frac{1}{2}} \cdot exp(- \frac{1}{2} x^2)$$
Plotting it I get the following result:

This however does not help me in the decision in which number range I should use, maybe $[-2,2]$? This seems too arbitrary, what is the correct approach here?

In my programming langauge I have a random generator for generating normal variates.
Comment: @Mahoni: If your programming language has a function, let it do its stuff. It will presumably not limit outputs to $[-2,2]$, since such events, for $P(|Z|>2)$, though smallish, is non-zero.
Comment: What do you mean by 'will be used as function input', can you talk more about the specific sampling that you're planning on doing?  There are several well-established techniques for generating normal deviates; see, e.g., http://en.wikipedia.org/wiki/Normal_distribution#Generating_values_from_normal_distribution ...
Comment: @StevenStadnicki I have defined the 1-dimensional Gaussian function in my question. In order to sample it, I need input values $x$ in order to get a sample result. That's what I meant.
Comment: If you are doing things from scratch, I would suggest the Box-Muller Method, easy to find on the web. Various pieces of software, like Excel, will also do the job, with minimal programming.  Calculating the *density* for various input values $x$ is not too useful, unless you are merely graphing.
Comment: @AndréNicolas I am not doing this from scratch. My programming language has already a function for generating normal variates.
Comment: @AndréNicolas Okay then I got it!
Answer: If this is a standard normal [-2, 2] only contains 95.4 percent of the data [-4, 4} puts it well over 99%.  Six sigma would be [-6, 6].


Install etckeeper via ansible, and perform first commit at end of playbook

Question: I'm using ansible to provision a server. One of the roles installs etckeeper, which automatically creates the git repo and makes the first commit.
If many tasks run after that (which install via apt or perform configuration changes), then the repo is a mess of commits - before I even start using the server.
I want one commit at the end of the ansible playbook, triggered via notify: etckeeper commit.
Is that possible?
Comment: Where are the commits coming from?
Comment: @MichaelHampton From etckeeper. During the playbook's tasks I install lots of stuff (via apt) and every time etckeeper makes a commit.
Comment: You mean from apt? OK, now I get it. apt is running etckeeper.
Comment: @MichaelHampton Yeah from what I understand, apt has some pre- and post- install / uninstall triggers, and etckeeper uses them to know when something was changed, and then automatically commits the whole of `/etc`. But during provisioning, that results in dozens of useless commits, so I'm hoping there's a way to only commit once at the very end of the ansible playbook.
Answer: From the manual:

Here's how to disable the automatic commits after each apt run, while still
  letting it git add new files:
rm /etc/etckeeper/commit.d/50vcs-commit

Once the auto commit feature is disabled you can trigger the script via Ansible at the end of the play.
Comment: But then it won't perform commits again. The idea is to disable it only for a while, not forever.
Comment: Well, you could run a command like `mv /etc/etckeeper/commit.d/50vcs-commit /etc/etckeeper/commit.d/.50vcs-commit` at the beginning of the playbook and a similar at the end. In any way I don't see the point using etckeeper and Ansible.
Comment: That's a decent workaround.
Comment: Why not use ansible and etckeeper? You provision a server with everything required, including etckeeper.
Comment: Because the content of `/etc` is already managed by Ansible. Ansible playbooks should be under version control. So there are two systems keeping track of the config. The info in etckeeper is out of context as etckeeper cannot know why Ansible changed something in etc. But that is just my opinion.
Comment: Ideally yes. But in real world scnearios, where something has to be done right away, and there's no time to upgrade the ansible infrastructure... then you just do it, and rely on etckeeper. Clean up the mess afterwards.


Relationship between ROC curve and statistical significance in comparison of two groups

Question: My question is about any possible relationship between the significance of a comparison test (Mann-Whitney U) and the ROC curve.
If the comparison test is strongly significant, should we expect a better ROC curve, and consequently better NPV, PPV etc.?
In details: I'm comparing the blood results between 2 groups for a predictive model. My pilot data, from 50 samples, showed statistical significance (Mann-Whitney U test) and the ROC curve showed good specificity, sensitivity, PPV and NPV.
Afterwards, I ran the same tests with 200 samples. The Mann-Whitney U test showed an even better statistical significance (far better). However, from the ROC curve only the specificity was of value, but not as good as the one from the pilot results. The sensitivity, PPV and NPV have worsened tragically!
I was expecting with bigger numbers and better statistical significance to have a better ROC.
Is there an explanation for that?
Comment: How many degrees of freedom (parameters) you have in your model ?
Answer: I would accuse overfitting. With N=50, there is a risk of overfitting if your model has too many degree of freedom. It's easier to fit 50 subjects than 500 subjects.
Concerning your feeling of contradiction with the better p-value of your Mann-Whitney U, it's perfectly normal to have a better level of evidence for the difference between groups when N increases. Let's say that in reality, there is constant difference of 5% of blood pressure between your two groups, if you are not unlucky, increasing N should increase your p-value. That's why a better p-value does not mean that the difference between groups or that it's easier to discriminate subjects.
Answer: Because you have a continuous test, sensitivity, specificity, NPV, PPV just get in the way.  So does the ROC curve.  It provides no insights here, although it is traditional.  Just stick to the idea of separation, which the concordance probability (c-index), Wilcoxon-Mann-Whitney, and Somers $D_{xy}$ rank correlation equivalently quantify.  The c-index (which happens to be the ROC area although in some ways this detracts from the c-index) like $D_{xy}$ is a unitless measure of separation.  You are right that significance will generally be greater for larger $N$.  But I would do the following:

Use a nonparametric smoother such as loess to estimate the relationship between X and the probability of a positive diagnosis
Describe the degree of relationship between the X and the diagnostic outcome using c or $D_{xy}$
De-emphasize P-values

For more details see the link to Biostatistics for Biomedical Research  at the top of http://biostat.mc.vanderbilt.edu/ClinStat - read chapter 18.
If you really want to test $H_{0}$: ROC area = 0.5 (absence of diagnostic information), the Wilcoxon-Mann-Whitney 2-sample rank-sum test is definitely the test to use.


Fixed Point Scheme

Question: I want a fixed point scheme that will converge for all values of ' $a$ ' .
$$x = \sin(x) - ax + 30$$
I have tried a couple of options but none works for all values of '$a$'
Comment: Is $x$ in radians ?
Comment: Not provided, but i think its in degrees.
Comment: I have even tried   x =  sin(x) + 30 / (1+ a)

But it doesn't work as well.
Comment: Why would you think that?  In any problem not specifically involving angles, the argument of the trig functions should be in radians.  In any case, that really is not important to this problem.
Comment: I was doing the other problem from same problem set where x was in degrees so i assumed here too is the case.
Comment: @user247327: how do you know ?
Comment: Note that as the sine is small compared to $30$, the solution is always very close to $30/(1+a)$.
Comment: What is your starting value ?
Answer: $x=(\sin x + 30)/(1+a)$ (note the parentheses) is the natural try and will work well when $a \not \in [-2,0]$  When $a$ is in that interval the derivative can be greater than $1$ in absolute value.  In that case you want $x=\arcsin ((1+a)x-30)$ but I don't see a way to get one expression that works for all $a$.
Comment: Another proposed solution was
 x =  ( sin(x) - xcos(x) +30 )/(1 + a - cos(x))
Comment: But it fails as well

Fixed Point Scheme


How to solved this 'Error output from CocoaPods" problem?

Question: When I am using vs code that time ios simulator worked fine but When the same project wanted to run on Android Studio for Flutter application development that time I faced this kind of problem. I could not understand what will be the proper solution for this.
Running pod install...
CocoaPods' output:
↳
      CDN: trunk Relative path: CocoaPods-version.yml exists! Returning local because checking is only performed in the repo update

Error output from CocoaPods:
↳
        WARNING: CocoaPods requires your terminal to be using UTF-8 encoding.
        Consider adding the following to ~/.profile:

        export LANG=en_US.UTF-8

    /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/unicode_normalize/normalize.rb:141:in `normalize': Unicode Normalization not appropriate for ASCII-8BIT (Encoding::CompatibilityError)
        from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.2/lib/cocoapods/config.rb:166:in `unicode_normalize'
        from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.2/lib/cocoapods/config.rb:166:in `installation_root'
        from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.2/lib/cocoapods/config.rb:226:in `podfile_path'
        from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.2/lib/cocoapods/user_interface/error_report.rb:105:in `markdown_podfile'
        from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.2/lib/cocoapods/user_interface/error_report.rb:30:in `report'
        from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.2/lib/cocoapods/command.rb:66:in `report_error'
        from /Library/Ruby/Gems/2.6.0/gems/claide-1.0.3/lib/claide/command.rb:396:in `handle_exception'
        from /Library/Ruby/Gems/2.6.0/gems/claide-1.0.3/lib/claide/command.rb:337:in `rescue in run'
        from /Library/Ruby/Gems/2.6.0/gems/claide-1.0.3/lib/claide/command.rb:324:in `run'
        from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.2/lib/cocoapods/command.rb:52:in `run'
        from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.2/bin/pod:55:in `<top (required)>'
        from /usr/local/bin/pod:23:in `load'
        from /usr/local/bin/pod:23:in `'
    /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/unicode_normalize/normalize.rb:141:in `normalize': Unicode Normalization not appropriate for ASCII-8BIT (Encoding::CompatibilityError)
        from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.2/lib/cocoapods/config.rb:166:in `unicode_normalize'
        from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.2/lib/cocoapods/config.rb:166:in `installation_root'
        from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.2/lib/cocoapods/config.rb:226:in `podfile_path'
        from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.2/lib/cocoapods/config.rb:205:in `podfile'
        from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.2/lib/cocoapods/command.rb:160:in `verify_podfile_exists!'
        from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.2/lib/cocoapods/command/install.rb:46:in `run'
        from /Library/Ruby/Gems/2.6.0/gems/claide-1.0.3/lib/claide/command.rb:334:in `run'
        from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.2/lib/cocoapods/command.rb:52:in `run'
        from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.2/bin/pod:55:in `<top (required)>'
        from /usr/local/bin/pod:23:in `load'
        from /usr/local/bin/pod:23:in `'

Error running pod install
Error launching application on iPhone 12 Pro Max.

What is the problem and why it's not working properly?
Comment: Does this help? https://stackoverflow.com/a/59409064/15117201
Comment: Does this answer your question? [iOS - CocoaPods requires your terminal to be using UTF-8 encoding - after latest flutter upgrade](https://stackoverflow.com/questions/59405671/ios-cocoapods-requires-your-terminal-to-be-using-utf-8-encoding-after-latest)
Answer: finally i have solved this with below steps
export LANG=en_US.UTF-8
opened project in Xcode and cleaned it.
opened iOS folder in mac terminal and ran pod install
it gave me warming of using ios 9.0 so i updated it to 10.0
ran flutter build ios
project build successfully
opened Runner.xcworkspace in xode
clicked on run - this time Xcode again installed pod automatically
and Solved.


Animate easing for scrollTop

Question: How to animate easing for scrollTop? I'm using scrollTop to move div element when site is scrolled. I want div element to move smoothly not jumping so sharply.
Here is the code:
jQuery(window).scroll(function() {
    if (jQuery(window).scrollTop() > 20 ) {
                    jQuery('.topBar').css({
                    'position':'fixed',
                    'top':-40,
                    'bottom':""
                });
   }
    else {
                    jQuery('.topBar').css({
                    'position':'fixed',
                    'top':0,
                    'bottom':""
                });
    }
});

Answer: did you try animating the topBar tag then?
jQuery(window).scroll(function () {
    if (jQuery(window).scrollTop() > 20) {
        jQuery('.topBar').animate({
            top: "40"
        }, 300, function () {
            jQuery(this).addClass('scrolled');
        });
    } else {
        jQuery('.topBar').animate({
            top: "0"
        }, 300, function () {
            jQuery(this).removeClass('scrolled');
        });
    }
});

I've created following fiddle to illustrate what i mean:
http://jsfiddle.net/2d3mxm5a/
Comment: It does not seem to work properly. Tried with this: `jQuery(window).scroll(function () {
    if (jQuery(window).scrollTop() > 20) {
        jQuery('.topBar').animate({
            "top": "-40",
            "position":"fixed"
        }, 300, function () {
            jQuery(this).addClass('scrolled');
        });
    } else {
        jQuery('.topBar').animate({
            "top": "0",
            "position":"fixed"
        }, 300, function () {
            jQuery(this).removeClass('scrolled');
        });
    }
});
` It takes couple seconds after scroll to move topBar div.
Comment: 1) your words were - "div element to move smoothly not jumping so sharply." - this is it; 2) could you show modifications in jsfiddle as well - it's easier to understand
Comment: And after I scroll to top of the page it does not anymore return toBar div to normal position as it did before.
Comment: In your jfiddle example it does exactly the same: after scrolling it takes few seconds to script to move div. Why? And to return div in up position it takes even longer.
Comment: Okey. By adding stop() it fixes the lag delay: jQuery('.topBar').stop().animate({..

Animate easing for scrollTop


How to calculate the standard deviation for a Gaussian Process?

Question: I am quite new to Gaussian processes. A Gaussian Process looks like the following:

Where the dark blue line denotes the mean, and the filled-area denotes the mean+std and mean-std respectively.
From what I know, we can calculate the predicted mean function as follows

$K$ denotes the kernel used
$x_*$ denotes the x-coordinate to be
predicted
$x_d$ denotes all the 'training data'/previously sampled
data):

$$ m( y_* | y_d) = \mu(x_*) + K(x_*, x_d) K(x_d, x_d)^{-1} (y_d - \mu (x_d)) $$
and the covariance function as follows:
$$ C(y_* | y_d) = K(x_*, x_*) - K(x_*, x_d) K(x_d, x_d)^{-1} K(x_d, x_*) $$
As I am currently new to Gaussian processes and try to understand the process before going into implementations, I started working through this blog-post.
Here, the author calculates the following to end up with the standard-deviation:
K_ss = kernel(Xtest, Xtest)
K_s = kernel(Xtrain, Xtest, param)
K = kernel(Xtrain, Xtrain, param)

L = np.linalg.cholesky(K + 0.00005*np.eye(len(Xtrain)))
Lk = np.linalg.solve(L, K_s)

s2 = np.diag(K_ss) - np.sum(Lk**2, axis=0)
stdv = np.sqrt(s2)

My initial thought was that the covariance-function $C(y_* | y_d)$ can be used to calculate the standard deviation for each sampled data point in the above graph. However, looking at the code, I don't quite understand how this is done.
So my question is: How is the standard deviation calculated? And how can I then arrive at a graph like the above one?
Comment: I'm not sure I understand your question. You've written the underlying closed-form equation and an implementation to produce the above plot. Is there a more specific part that you don't understand?
Comment: @KevinYang basically, why does the above code produce the above graph? Specifically, I don't understand what the code does / why it arrives at the same closed-form equation?
Answer: The closed form equation for the predicted covariance inverts $K(x_d, x_d)$. However, using the Cholesky decomposition is faster and more numerically stable than directly taking the inverse. You can see the procedure laid out in Algorithm 2.1 of Gaussian Processes for Machine Learning. However, they don't show why they're equivalent, so I'll sketch it out here.
First
The closed-form equation gives a $n$ x $n$ covariance matrix for $d$ test points. The code only cares about it's diagonal. $K(x_*, x_*)$ is the $n$ a $n$ prior covariance between the test points, but the code extracts
np.diag(K_ss)

Note that
np.sum(Lk**2, axis=0)

is equivalent to:
np.diag(Lk.T @ Lk)

In other words,
Lk.T @ Lk

is somehow equivalent to
$$ K(x_*, x_d) K(x_d, x_d)^{-1} K(x_d, x_*) $$
The Cholesky decomposition of $K$ produces a lower triangular matrix $L$ with real positive diagonal entries such that
$$K = LL^T$$
Let $k_s = K(x_d, x_*)$ so that the least squares (np.linalg.solve) step outputs:
$$L_k = (L^TL)^{-1}L^Tk_s$$
$(AB)^T = B^TA^T$, $(AB)^{-1} = B^{-1}A^{-1}$, and $(A^{-1})^T = (A^T)^{-1} = A^{-T}$ , so
\begin{align}
L_k^TL_k &= k_s^T L [(L^TL)^{-1})]^T(L^TL)^{-1}L^Tk_s\\
L_k^TL_k &= k_s^T L (L^{-1}L^{-T})^TL^{-1}L^{-T}L^Tk_s\\
L_k^TL_k &= k_s^T L L^{-1}L^{-T}L^{-1}L^{-T}L^Tk_s\\
L_k^TL_k &= k_s^T L^{-T}L^{-1}k_s
\end{align}
From the definition of the Cholesky decomposition:
$$ K^{-1} = (LL^T)^{-1} = L^{-T}L^{-1}$$
Therefore:
$$ L_k^TL_k = k_s^T K^{-1} k_s $$
Finally, note that in the code, they add a small diagonal element to the training covariance so that:
$$K = K(x_d, x_d) + \sigma_n^2I$$.
The small diagonal element represents an estimate of the observation noise. That is, we assume that the observations $y$ are normally distributed with mean $f(x)$ and variance $\sigma_n^2$. Numerically, this helps to guarantee that the training covariance is positive definite.
Comment: I haven't talked about the actual plotting code, since you didn't post that part, but we can discuss that too if you're confused about that.
Comment: @DaveTheAl You should implement the predictive mean using cholesky too :-)
Comment: Dude, thanks for the awesome answer! :) Weirdly, I understood the plotting part. I had re-implemented everything using the usual matrix-inversion; I think I'll try the cholesky myself next. Thanks again! :)


Como usar o virtualenv do Python no Windows

Question: Após instalado com sucesso o virtualenv com o comando:
pip install virtualenv

Quando vou criar uma virtualenv com o comando
virtualenv -p python3 coleta_dados

Ele me traz o seguinte
'virtualenv' não é reconhecido como um comando interno
ou externo, um programa operável ou um arquivo em lotes.
O que falta fazer?
Estou usando o python 3.10.2
Comment: Um detalhe importante em relação à resposta aceita: `venv` e `virtualenv` são coisas diferentes - o primeiro vem junto da biblioteca padrão de Python, o segundo é um pacote externo que se instala com `pip`. Ambos servem pra mesma coisa mas apresentam funcionamento distinto. [Essa resposta](https://stackoverflow.com/a/41573588/11161432) (do SO em inglês) se aprofunda na diferença entre essas e outras ferramentas de gerenciamento de ambientes virtuais de Python.
Comment: python -m venv minhavenv
Comment: Deu certo! :) Adiciona a resposta por favor.. Faço questão de votar
Answer: Para criação da venv você deve "chamar" o python, o comando da venv e depois nomea-la, conforme abaixo:
python -m venv minhavenv

Answer: No caso a criação de uma virtualenv não precisa chamar python.
Depois de instalar a virtualenv o comando que você precisa dar é:
virtualenv nomedavirtualenv

Para ativar a virtualenv criada você precisa acessar o arquivo activate da virtualenv com o seguinte comando (estando no diretório que ela foi criada):
nomedavirtualenv\Scripts\activate

Note que a resposta mais votada acima cria uma venv, que não é a virtualenv, são ferramentas de gerenciamento de ambientes diferentes.