Is there any example of 2-step predictive model?(i.e. classification model coupled with regression models for each subclass)

Question: I have a large dataset with 10,000+ individuals and many many biological features (>5000). And I want to use these features to build a linear model (e.g. elastic net) to predict their clinical outcome (e.g. time-to-death).
The problem is, these individuals can be further classified into many sub-groups (i.e. different diseases), and therefore it might not feasible to get a universal model to predict the time-to-death in all these patients. However, the aim is to predict the time-to-death of any new patients only based on these biological features.
Edit: there are "classification" information for each sample and the model works well in predicting inside of each class. However, the classification information here are fully imputed based on the biological features (as what I used to build the prediction model), with some human curation.
Therefore, I'm wondering if it is a good idea to train a two-steps model: First, build a classification model to predict which subtype the individual belongs to. And second, train multiple linear models for each subtype.
In this way, for any new patient, I can first run the classification model to get the probability/weight for each subtype and then predict the time-to-death using different linear models and weight the result based on step 1.
My question is, is this a good idea? If so, is there any reference for this method?
Thank you in advance!
Comment: Yes, this is a classic latent variable approach. $p(\text{TTD} \mid \text{patient}) = \sum_{\text{subtype}} p(\text{TTD} \mid \text{subtype} , \text{patient})p(\text{subtype}) \mid \text{patient})$
Comment: See also https://stats.stackexchange.com/questions/245902/is-there-any-algorithm-combining-classification-and-regression/245910#245910
Answer: My understanding is that this is best done with a combined model that evaluates together both the probability of class membership along with the associations of class membership and covariate values with outcome. Larssen (Biometrics 60: 85–92, 2004) developed such an approach with categorical predictors of class membership. You maximize the overall (partial) likelihood of the data combining both the class-membership model and the survival model. That avoids problems that can arise from a 2-step model and its fixed assignments of potentially highly uncertain class memberships. As a more recent example, Liu et al. (Computational Statistics and Data Analysis 91: 40–50, 2015) extended this to arbitrary predictors and individual longitudinal data in parametric Weibull models, and note why a combined approach is better than a 2-step model.
I don't know of any off-the-shelf programs to do this combined class/survival analysis, however. Also, I understand that these approaches require a pre-specification of the number of classes. There might be Bayesian approaches that would also model the number of classes, but that's far beyond my expertise.
Besides the general cautions expressed in the post on latent class models linked in a comment by @rep_ho, make sure that the way you try "to predict the time-to-death of any new patients only based on these biological features" makes biological and clinical sense. These sound like cancer outcome data together with tumor gene-expression data, but even if they are something else the following principles still hold.
Make sure that the "biological features" include all the associated critical clinical characteristics.
First, there presumably is clinical assessment of the "different diseases" at question. That clinical assessment should be a primary factor in class assignment. Tumors originating in the same organ can have well defined subtypes, as in breast and lung cancer. You might want to start by assessing how gene expression values are associated with these major clinical distinctions among tumor types.
Second, each type of cancer also has its own further breakdown into stages specifically related to outcome for that type of cancer. Ignoring that information (either the overall staging, or the factors that go into defining the stages) is done at your peril.
Third, the same type of cancer can be treated with different therapies. For example: primary therapy of surgery versus chemo (and/or radio) therapy, radiation and/or chemotherapy adjuvant to surgery, classic systemic chemotherapy versus therapy "targeted" against particular molecular aspects of a tumor versus more recent immunotherapies. There is no reason to expect that molecular characteristics of a tumor will have the same associations with outcome for different therapies received even in a single tumor type. You might need to examine interactions of your thousands of biological characteristics with therapy in terms of outcome.
If you are using an approach like elastic net, you might best be served by not penalizing the critical clinical variables, reserving your variable selection and penalization for the other markers like gene-expression values.
Comment: Hi EdM, thank you so much for your reply! The reference is really helpful.
One thing I forgot to mention (now updated to the question) is that: the classification information in the dataset are fully imputed based on the biological features (as what I used to build the prediction model), with some human curation.
In another word, if I just build different models for each class, I will be still unintentionally doing a 'two step model' with some mixture of human curation. That's why I want to do the clustering myself.
Comment: Another thing I don't understand is that why this latent class approach is not popular? --considering that most (if not all) of real-life samples have underlying groups and heterogeneity. Does that mean this approach actually doesn't work well?
Comment: @AlbertYing modeling based on knowledge of the subject matter is generally preferred to machine-learning methods whose results can difficult for humans to understand, particularly in clinical situations. If I were treating lung cancer, I would want a good model specific to types of lung cancer whether or not a related model worked for prognostication on colon cancer. In that sense, I think most clinicians would prefer a 2-step approach, distinguishing clinical/biological subclasses and then performing survival analysis within each class.
Comment: @AlbertYing [latent-class analysis](https://en.wikipedia.org/wiki/Latent_class_model) isn't "unpopular"; it has a long history in general. The question here is when it provides something useful beyond standard clinical information. Combining large numbers of cases with thousands of predictors, as with The Cancer Genome Atlas, is relatively new. Thus it's only been recently that one could envision mining large amounts of biological/clinical data to find latent classes that cut across clinical classes. How much machine learning will add to clinical categorization is the open question.


password-less login using ssh agent

Question: I can copy the rsa key to the remote server for passwordless log-in.
But I was told that there is another way to add this functionality using ssh-agent.
I have run the commands generated by ssh-agent command. I did tried to add the key using ssh-add
<code>$ ssh-add
Enter passphrase for /home/shantanu/.ssh/id_dsa:
Identity added: /home/shantanu/.ssh/id_dsa (/home/shantanu/.ssh/id_dsa)
</code>
Does ssh-agent work the way I am trying to make it work?
Comment: Are you talking about sshing from client to server without a password, or sshing from client to server 1, then sshing from server 1 to server 2 without a password?
Answer: If your key has no passphrase (usually a bad thing) you don't need ssh-agent.  You just put the public key into the authorized_keys file and off you go.
If however, your key does have a passphrase then you use ssh-agent (as well as putting the public key into the authorized_keys file), add the passphrase once (as you did above), and then for the rest of that session you don't have to use it again.  For a new session you will have to add it again, this is usually a minor inconvenience.
Answer: The reason why you want this is propably because you want to do something automated on a remote server. Using ssh-agent or something similar is possibly no option, since you have to input the passphrase in an automated way, too.
Using keys without passphrase will do the job, but that is dangerous. So if you do it without passphrase:

Don`t use a priviledged account
You can limit the action to a single command in the authorized_keys file
If you need to copy things:
Use a transfer account and use another local account to get the data from the transfer acccount

password-less login using ssh agent


Maintaining checkbox state after an error

Question: I am using Oracle ApEx and have a standards SQL Report with the following apex_item.checkbox call, i.e.:
select
apex_item.checkbox(1, empno) cbox,
"EMPNO",
"ENAME",
"JOB",
"MGR",
"HIREDATE",
"SAL",
"COMM",
"DEPTNO"
from "EMP"
where
(
instr(upper("ENAME"),upper(nvl(:P1_REPORT_SEARCH,"ENAME"))) > 0 or
instr(upper("JOB"),upper(nvl(:P1_REPORT_SEARCH,"JOB"))) > 0
)

My problem is, apart from having this report within one of my pages, I also have other items on the page that are required fields, so when the user clicks on 3 of the 10 checkboxes based on the above SQL and submits the page, the user is presented with an error, indicating that an item on the page is required.
Now when the user is presented with this error, the 3 out of 10 checkboxes that were checked are now unchecked.
Can I maintain checkbox persistence/state based on the above scenario? as I don't want the user re-checking the records they already checked.
I am interested in solving this with an Oracle ApEx means if possible. However, a jQuery approach may also work.
Answer: i found some way to do this, with a mix of apex and jquery:

On submit process: get the state of the checkboxes (through apex_application) and store them through apex_collections
After resfresh: get the values through an ajax callback and set them again with some javascript code.

I made a report (Report 1), based on emp, with your query (but left out the where-clause).

My on-submit process where i get the checked boxes (through apex_application you only get the checked ones!), and keep them in a collection. This collection is created or emptied each submit. I left the debug
messages in, so you might track them.
Oh, and the value stored is empno, since you based the checkbox item on that column, and not 1 or 0.
apex_debug_message.log_message('on submit point');
APEX_COLLECTION.CREATE_OR_TRUNCATE_COLLECTION('COLL_REPORT1');

FOR i IN 1..APEX_APPLICATION.G_F01.COUNT LOOP
apex_debug_message.log_message('loop chk: '||i||': '||TO_NUMBER(APEX_APPLICATION.G_F01(i)));
   APEX_COLLECTION.ADD_MEMBER(p_collection_name => 'COLL_REPORT1',
                              p_n001 => TO_NUMBER(APEX_APPLICATION.G_F01(i))
                              );
END LOOP;

Then create an ajax callback process:
I make a json array here, which simply holds the values of the checkboxes, and helps me easily parse the values afterwards. Collection is truncated after retrieval.
DECLARE
   v_first BOOLEAN := TRUE;
   v_json VARCHAR2(4000);
BEGIN
   v_json := '[';
   FOR r IN (SELECT n001 FROM APEX_collections
              WHERE collection_name = 'COLL_REPORT1')
   LOOP
      apex_debug_message.log_message('stored value: '||r.n001);
      IF NOT v_first THEN
         v_json := v_json ||',';
      ELSE
         v_first := FALSE;
      END IF;
      v_json := v_json || r.n001;
   END LOOP;

   v_json := v_json || ']';

   APEX_COLLECTION.TRUNCATE_COLLECTION('COLL_REPORT1');

   htp.p(v_json);
END;

Then the values need to be retrieved and set, which is done through a dynamic action.

Event: after refresh
Selection type: Region
Region: (your report    region, mine is Report 1)
No condition

The code:
   var oDBGet = new htmldb_Get(null, &APP_ID., 'APPLICATION_PROCESS=get_checked_boxes', &APP_PAGE_ID.);
   var arrBoxes = jQuery.parseJSON(oDBGet.get());

   $.each(arrBoxes,
          function( intIndex, objValue ){
             $("input[name='f01'][value='"+objValue+"']").attr("checked","checked");
          });

This code simply calls the ajax callback and parses the returned string as a json object (which is an array due to [value,value,value] syntax).
I then loop over this array and set the values on the input elements with name f01 (dynamically created checkboxes, this is the based on the id given to apex_item.checkbox), and where the value equals that of the value we have stored. Through attr the box gets checked!
Here's hoping i didn't overdo it :)
Comment: Hey Tom, just firstly want to say that your response and very detailed and helpful response was very much appreciated and also solved my problem. So thank you. If I could score you higher, I would. Hope you can help me again for possibly other Apex questions. Thanks again.
Comment: Thanks! I myself have only been working in Apex for a good 2 months now and things really start falling in to place more and more. I've been through some intense searching for seemingly stupidly simple problems too, and will gladly help wherever i can :)


Geometric description of set of points satisfying $\mathrm{Im}(z)>0$

Question: How can we describe geometrically the set of points $z$ satisfying the condition $\mathrm{Im}(z)>0$ where $z$ is a complex number?
Comment: Welcome to math.SE: since you are new, I wanted to let you know a few things about the site. In order to get the best possible answers, it is helpful if you say in what context you encountered the problem, and what your thoughts on it are; this will prevent people from telling you things you already know, and help them give their answers at the right level.
Answer: If we write $z=x+yi$ with $x,y\in\mathbb R$ and draw this on the plane, we see that this is just the upper half plane, excluding the horizontal axis.
Answer: Hint: If $z=x+yi$, $x,y\in \mathbb{R}$ and $\Im z>0$ then $y>0$ and $x\in \mathbb{R}$. What does this tell you?


How to configure create-react-app typescript to automatically use ts-loader for typescript based node modules?

Question: So I have a project called client. The client requires components and services from the core. The core is a typescript project that hasn't been compiled and built yet. In order to develop the client application faster I'm required to develop both the core and client at the same time. with this regard I created an npm link into the core within client. However, when I use the core codes I get an error message.
Module parse failed: Unexpected token (7:34)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders

I suspect that the webpack isn't using the appropriate loader to build the typescript node module. Is there any way of solving this issue without ejecting the config files.
Answer: The typescript version of create-react-app is using the babel-loader to transform typescript into javascript.
The problem you are having is here:
test: /\.(js|mjs|jsx|ts|tsx)$/,
include: paths.appSrc,
loader: require.resolve('babel-loader'),

it only compiles ts|tsx in the paths.appSrc folder, which is the main src folder, but your linked module is outside this folder.
You can fix it by editing the include rule or removing it altogheter, so you have to eject.
If you don't want to eject you can add a script in your build chain that modifies the webpack.config.js file under node_modules\react-scripts\config after the npm install, but this is a bad practice.
This is what I am using:
import * as fs from 'fs';

export function deleteLineFromFile(props: { path: string; lineToRemove: { index: number; value: string } }) {
  const data = fs.readFileSync(props.path, 'utf-8');
  const array = data.split('\n');
  const value = array[props.lineToRemove.index - 1].trim();

  if (value === props.lineToRemove.value) {
    array.splice(props.lineToRemove.index - 1, 1);
    const newData = array.join('\n');
    fs.writeFileSync(props.path, newData, 'utf-8');
  }
}

deleteLineFromFile({
  path: 'node_modules/react-scripts/config/webpack.config.js',
  lineToRemove: { index: 384, value: 'include: paths.appSrc,' },
});

Comment: You should use patch-package. Way way better option.


structure in context of ultraproduct

Question: Ultraproduct is defined as $$\prod_{i \in I} M_i $$
I know that structure is usually of form $(A, \sigma, I)$, but in this context, what exactly is structure, and how do we get the cartesian product?
Edit: so $M_i$ is structure here according to the definition of ultraproduct, but how can structures be combined to form cartesian product?
Comment: Consider providing some context to this question.  As it stands I don't really know what you are asking about.
Comment: Ordinarily one is working with $L$-structures $M_i$ for some first-order language $L$. The Cartesian product is as usual the set of all function from $I$ to the union of the $M_i$ (or more properly to the union of the underlying sets of the $M_i$) such that $f(i)\in M_i$ for all $i$.
Comment: So are we only looking for the domain of the structure by saying $M_i$?
Answer: We give a fairly formal description, followed by more informal remarks at the end.
Ordinarily, the $M_i$ are $L$-structures for a first-order language $L$.
Denote the underlying set of $M_i$ by $|M_i|$.
Let $D$ be an ultrafilter on $I$.
Consider the product $\prod_{i\in I} |M_i|$. This is the set of all functions $f$ from $I$ to the union of the $|M_i|$ such that $f(i)\in |M_i|$ for all $i$.
If $f$ and $g$ are in $\prod_{i\in I} |M_i|$, we say that $f$ and $g$ are equivalent modulo $D$ if $\{i|f(i)=g(i)\} \in D$. This is an equivalence relation.
The underlying set of the ultraproduct $(\prod_{i\in I} M_i)/D$ is the set of equivalence classes of $\prod_{i\in I} |M_i|$ under the above equivalence relation. Let |U|$ be this set of equivalence classes.
Now it remains to define  the right structure $U$ with underlying set $|U|$ as described above. So we have to give interpretations for all the constant symbols, function symbols, and relation symbols of $L$.
Constant symbols are the simplest. Let $c$ be a constant symbol of $L$. Then $c$ has an interpretation $c_i$ in $M_i$. We interpret $c$ in $U$ to be the equivalence class of the function $f$ such that $f(i)=c_i$.
Now suppose that $F$ is a say binary function symbol of $L$. We want to interpret $F$ in $U$. Let $F_i$ be the interpretation of $F$ in $M_i$. We will describe the interpretation $F_U$ of $F$ in $U$.
Let $\bar{f}$ and $\bar{g}$ be elements of $|U|$, that is, equivalence classes of functions. Then $F_U(\bar{f},\bar{g})$ is the equivalence class of the function $h$ such that $h(i)=F_i(f(i),g(i))$ for all $i$. We do need to check that this definition, which appears to depend on our choice of representatives for $\bar{f}$ and $\bar{g}$, is in fact independent of the choice of representatives.
Interpretations of relation symbols are handled in a similar way.
Remark: Think of elements of the product as "sequences" such that the $i$-th entry is in $|M_i|$. If we have two such sequences, we say they are equivalent if the set of $i$ on which they agree is in $D$, informally that the set on which they agree is "large." Think of sets in the ultrafilter as having measure $1$, and their complements as having measure $0$. "Measure" is kind of stretching terminology, since we almost always only have finite additivity. But it is useful to think of $f$ equivalent to $g$ if they agree "almost everywhere."
Then the structure on the ultraproduct is obtained in the natural way, "pointwise."  Except, of course, that we identify sequences that are equal almost everywhere. Constructions of this type are also quite common in analysis.
An important special case is the ultrapower $M^I/d$, where all the $M_i$ are the same. Take or example the structure $ \mathbb{Z}^I/D$, where $I$ is the set of natural numbers, and $D$ is a non-principal ulrafilter. The elements of the ultrapower are just equivalence classes of integer-valued sequences. We add, multiply equivalence classes of sequences essentially by pointwise addition and multiplication, except that two sequences that are equal almost everywhere are considered the same. This is crucial for the preservation of properties. For example, under pointwise multiplication, the product $\mathbb{Z}$ has plenty of non-trivial zero-divisors. But the ultrapower $\mathbb{Z}^I/D$ doesn't.
Comment: Small typo - in your definition of $F_U$ you should change to "for almost all i".
Comment: @Eran: One *could* say for almost all $i$. But I do mean to define $h$ exactly as written. Note that in the definition of $F_U$, it says that $F_U(\bar{f},\bar{g})$ is the **equivalence class** of the function $h$ such that $\dots$. (Then we have to check that other representatives $f'$, $g'$ give the same result.)
Answer: In the most general sense, suppose we have a family $\{ \mathfrak{A}_i \}_{i \in I}$ of structures over the same first-order language/signature, and an ultrafilter $\mathcal{U}$ on the index set $I$.  The ultraproduct of this family with respect to the ultrafilter $\mathcal{U}$ is defined according to the follow steps:

Define an equivalence relation $\sim$ on $\prod_{i \in I} A_i$ (where $A_i$ is the universe of the structure $\mathfrak{A}_i$) by $$( x_i )_{i \in I} \sim ( y_i )_{i \in I} \; \Leftrightarrow \; \{ i \in I : x_i = y_i \} \in \mathcal{U};$$
The universe of the ultraproduct $\mathfrak{A} = ( \prod_{i \in I} \mathfrak{A}_i ) / \mathcal{U}$ is then $( \prod_{i \in I} A_i ) / \mathord{\sim}$, the family of all $\sim$-equivalence classes.
For each $n$-ary function $f$ in the signature, the function $f^{\mathfrak{A}}$ is defined according to $$f^{\mathfrak{A}} ( [ x^1 ]_{\sim} , \ldots , [ x^n ]_\sim ) = [ y ]_\sim \; \Leftrightarrow \; \{ i \in I : f^{\mathfrak{A}_i} ( x^1_i , \ldots , x^n_i ) = y_i ) \} \in \mathcal{U};$$
For each $m$-ary relation $R$ in the signature, the relation $R^{\mathfrak{A}}$ is defined according to $$R^{\mathfrak{A}} ( [ x^1 ]_\sim , \ldots , [ x^m ]_\sim ) \; \Leftrightarrow \; \{ i \in I : R^{\mathfrak{A}_i} ( x^1_i , \ldots , x^m_i ) \} \in \mathcal{U}.$$

Of course we have to show that the results of (3) and (4) above are actually well-defined, but this is not too difficult.

structure in context of ultraproduct


ProtoRPC Message Class definition

Question: Im building a Cloud Endpoint for processing requests from a Firebase App. I want endpoint to recieve a Firebase database object like this:
<code>{
"$uid": "1234",
"$idCot": "abc",
"text": "TextHere"
}
</code>
So I create a Message class to handle this request:
<code>MyRequest(messages.Message):
     uid = messages.StringField(1, required = True)
     idCot = messages.StringField(2, required = True)
     text = messages.StringField(3, required = True)
</code>
but I cant find a way to create a valid Message Class in ProtoRPC to define that object because the "$" in the field name that Firebase adds.
Answer: Unfortunately, this just isn't possible with ProtoRPC today. The Endpoints Java framework does support this though.
Answer: The previous answer refers to the Endpoints Framework for Java, which is part of the Endpoints v2 release. Documentation is here: https://cloud.google.com/endpoints/docs/frameworks/java/
Comment: There's no "previous answer" - if you need to comment on a particular answer, do so, as a *comment* for that answer.

ProtoRPC Message Class definition


Creating event lists using nodequeue, static pages and dynamic dates

Question: I'm new to Drupal, with some familiarity in other CMSes. I'm currently attempting to create a series of event lists, and have met up with a few issues. The number of modules available for the system are confusing my Googling, as terminology isn't uniform across the web and I'm picking up information for everything but what I want. From reading in StackOverflow, I gather it's a common problem with Drupal. I'm looking for recommended resources or perhaps more direct help - advice on whether to learn the system fully despite this being such a simple/small job would be useful as well.
In summary:
Need an online system to create itineraries, lists of events containing location information and dates that are specific to unique clients/users. Employees access the backend, assemble an itinerary and provide a link to customers with an appropriately formatted, final page/document. Drupal is a CMS that is potentially going to be used for a future website, and "location information" would be a duplication of web content - this system would make for a neat way of populating the website with content whilst the main frontend is being developed.
What I need

locations are created as static nodes (pages)
access the backend with an interface that allows for the selection of these location nodes and compiles them into an ordered list
each node, despite being static, is associated with a date field (start and end) specific to each ordered list
lists are unique and independent, using the same static content to fill description fields but able to be linked with specific date information

Where I'm currently at

locations are created as static nodes (pages)
the itinerary is a nodequeue, where an employee creates a new one, adds location nodes and can control the order without technical know-how
display using Views, using unique URL per list
trying to find a way to relate the unique nodequeue with a pair of dates for each location
been playing around with custom content types/custom fields, but don't know how to define the relationship between the static/dynamic content
using Date API for javascript calendar pop-up in these custom fields

Any help would be much appreciated! I've tried to word the concept clearly here, and am  looking for a friendly pointer in the right direction. Even so much as the appropriate keywords so I can find tutorials would help - been a few long hours of head scratching.
Thanks in advance for any help!
Comment: Reworded on Drupal forums, might help here.

I'm trying to create unique itineraries that are specific to either a user or URL. An itinerary is a unique order of events, each associated with a start+end date (specific to each user). Events are stored as static pages and can be on any day.

For clarity: create a list of pre-existing static nodes (descriptions of events) that can be arranged in any order. Each event needs to be associated with a user/URL-specific date in this list.
Answer: Yup, adding my solution for the collective knowledge!

Created each location as an individual page (appropriately classified by taxonomy/etc. for site navigation)
Assigned the desired custom fields, most ended being display hidden
Created new content type, "itinerary-location-reference", using module "Reference" (for D7)
Within this content type, assigned custom fields for dates/visitor name/etc.
One of the custom fields needs to be a node reference
Referenced the location

This creates two nodes that are linked...one is the static location content, the other a node containing date/personal information. I then added this overall reference node to my nodequeues. Done.
I can see a few issues down the road regarding number of entries into the database, but apparently Drupal's good for a few million, so fingers crossed!


Complex Analysis. Showing absolute convergence of principal part of Laurent series for a holomorphic function.

Question: I am given that $f: D(P, r) \setminus \{ P \} \to \mathbb{C}$ is holomorphic. I want to show that the principal part of the Laurent series expansion for $f$ converges absolutely on $\mathbb{C} \setminus \{P\}$. Confused on how to proceed.
I know that the convergence is absolute on $D(P, r) \setminus \{ P \}$. I don't see how to extend the principal part to $\mathbb{C}\setminus\{P\}$.
Answer: The principal part gets better as you get farther from the pole, since it has only negative powers of $(z - P)$. Apply a comparison test, using the fact that the series is convergent at some point $z \ne P$.
In particular, you can use the fact that
$$\left|\frac{a_n}{(z - P)^n}\right| \le \frac{|a_n|}{r^n}$$
for $z \notin \mathbb{D}(P, r)$.
Comment: Thank you. I will try this out.
Comment: So basically take the limit of the right-hand side as $r \to \infty$?
Comment: No, because $r$ is just some fixed number.


Playing an octave lower on the same key

Question: we are doing a song that's originally on the key of F. Our singer would like to sing it on the key of G#. There's an electric guitar solo at the end of the song that I have to play. But after raising everything 3 steps up, nodes appear on the 23rd fret on the 1st string. I am wondering if I can still play the solo on G# and an octave lower. Would that affect the overall of the song? Or is it even correct to do so?
Comment: You don't necessarily have to play *all* the solo an octave lower. For example if the original jumps up a 5th somewhere, jump down a 4th instead to change to a different octave.
Comment: @Tim It's almost certainly a misspelling of "notes appear".
Comment: @Tim please don't stop the deep thinking... ...I strongly suspect the OP also didn't actually mean the 6th string but the 1st string, hence your answer is "too correct". But the terminology is well defined, so I'd say, answer every question as it was literally written – if that turns out to be not what the OP actually meant, their problem, they can always ask a new question.
Comment: I don't understand 'nodes appear...'  Are you using pinched harmonics, what? And even if they do appear, the location can't be much different from them appearing on fret 20 before, surely?
Comment: @tao it very much depends on the solo in question.  Sometimes you can move parts of a passage down the octave.  Sometimes you might move the whole thing down the octave.  Sometimes you might just change the melody slightly so that it has the same "flavour", but doesn't use the top notes any more.  Care to provide an example?
Answer: You can do whatever you want for a solo. Doing it at octave lower will just make it sound lower. It might not sound as prominent as a result. Basically, if you all you can do is play it there then just play it there. You won't be breaking any rules. If you don't like how it sounds there then you can change it accordingly but really how it sounds and feels is all that matters.
Answer: You could always try moving some or all of the notes onto different strings. for example, that 23rd fret bottom string appears on the 18th fret of the 5th string. You did mean the fattest string, I hope?

Playing an octave lower on the same key


how to install commerce_kickstart on an environment with PHP memory_limit less than 128M?

Question: I tried the full core install aproach and got a warning that I only had 96M on php memory_limitand kickstart needs 128M. tried anyway and sure enough got a memory error at the very end of the installation. I looked around my host and I'm sure I can't change that.
How can I make this installation work?
Answer: Try the methods listed here to increase the PHP memory_limit value
If none of those work, you may need a new host for that application.
Comment: I agree with David. Even if you found a workaround to installing Commerce kickstart, it also contains a large number of modules and will require at least 128M to operate on an ongoing basis. You are going to have to increase the amount of memory allocated to your site or get a new host.


Counterexample of $\lim_{x \to a^+} {1 \over f(x)} = 0$ iff $\lim_{x \to a^+} f(x) = \infty$

Question: The following proposition hold for $f(x)>0$
$\lim_{x \to a^+} {1 \over f(x)} = 0$ if and only if  $\lim_{x \to a^+} f(x) = \infty$
Is there an example where this is not true for some $f(x)<0$?
Comment: Negative-valued function can't diverge to positive infinity, but only possibly negative infinity.
Answer: $f(x)=-|\frac 1 {x-a}|$ is such an example.
Comment: We need $f(x)<0$.
Answer: What about
$$f(x)=-\frac1{|x|}\quad f(0)=-1$$
when $x\to 0^+$.
Comment: What is limit of $\frac 1 f$ as $ x\to 0+$?
Answer: If $\lim_{x\to a} 1/f(x)=0$, then $\lim_{x\to a}|f(x)|=\infty$, so if $f$ has a single, consistent sign near $a$, say $\sigma\in\{1,-1\}$, then $\lim_{x\to a}f(x)=\lim_{x\to a}\sigma|f(x)|=\sigma\lim_{x\to a}|f(x)|=\sigma\infty$. But if we remove that restriction on the sign, then there are counterexamples even with one-sided limits, e.g. $a=0$ and
$$f(x)=\begin{cases}
\displaystyle{1\over|x|}&\text{if }x\in\mathbb{Q}\\
\displaystyle{-1\over|x|}&\text{if }x\not\in\mathbb{Q}
\end{cases}$$
or, if you want only countably many discontinuities,
$$f(x)={(-1)^{[1/x]}\over x}$$
where $[\cdot]$ is the greatest integer function.


Modify puppet nodes.pp with regex based on network (facter) subnet coverage - needs peer review

Question: For the puppet experts out there, I am trying to modify my node.pp based on the facter network.
Example, I would like to have subnets 10.10.10.0 through 10.10.10.255 and 192.168.2.0 network to get the following puppet modules.
In my nodes.pp does this regex work?
node \d(10).(10).[0-10].[0-255] | \d (192).(168).(2).[0] $ {
  include "ntp"
  include "dhcp"
  include "common"
}

node default {
  include "common"
}

^ will above work? Thank You
Comment: Why don't you try it?
Answer: This will not work as shown. First, the regex is no good, but also node matchers are based on certname, which is the FQDN of the host. That's not to say you can't do it, but it would require some more work and it would require you do enter the realm of unsupported configuration. So, basically, you're on your own. This is what Puppet's documentation says:

Node statements match nodes by name. A node's name is its unique identifier; by default, this is its certname  setting, which in turn defaults to the node's fully qualified domain name.
Note on Non-Certname Node Names
Although it's possible to set something other than the certname as the node name (using either the node_name_fact or node_name_value setting), we don't generally recommend it. It allows you to re-use one node certificate for many nodes, but it reduces security, makes it harder to reliably identify nodes, and can interfere with other features.
Setting a non-certname node name is not officially supported in Puppet Enterprise.

No Puppet version was specified, so my answer is based on the latest (5.3) as of writing.
Instead, why don't you use your default node definition and combine it with logic based on the value of $::network?
node default {
  case $::network {
    /^(10\.10\.[0-10]\.[0-255]|192\.168\.2\.0)$/ : {
      include ntp
      include dhcp
      include common
    }
    default: { include common }
  }
}

This was tested by changing the includes to notices and changing network to $var and testing various values.
[aaron@localhost ~]$ cat network.pp
#$var='10.10.1.5'
$var='192.168.2.1'
case $var {
  /^(10\.10\.[0-10]\.[0-255]|192\.168\.2\.0)$/ : {
    notice('match')
  }
  default: { notice('default') }
}
[aaron@localhost ~]$ puppet apply network.pp
Notice: Scope(Class[main]): default
Notice: Compiled catalog for localhost.local in environment production
in 0.21 seconds
Notice: Applied catalog in 0.01 seconds

I included this so you get a good idea of how you can quickly see if something should work without spending effort deploying it to your Puppetmaster and testing with various hosts.


Inverse of elementary row operation explanation

Question: In my textbook, the following is found (regarding the inverse of an elementary row operation):
"Type III - Adding $k$ times row $p$ to a different row $q$ is reversed by adding $-k$ times row $p$ to row $q$ (in the new matrix). Note that $p \ne q$ is essential here."
I don't see why $p$ cannot equal $q$. Even if the two rows are equal, if I add the row and then add its inverse it will reverse the operation. What am I missing here? Thanks in advance.
Answer: If $r$ is your row, after adding it $k$ times to itself, you get $r+kr=(k+1)r$, which already changes it.
Trying to revert the operation will not give the original result. Subtracting $k$ times itself you get $(k+1)r-k(k+1)r=(k^2-1)r\ne r$
So it is essential that $p \ne q$


Django autocomplete: AttributeError: module 'dal_select2.models' has no attribute 'Model'

Question: My models.py:
from dal import autocomplete
from dal_select2_queryset_sequence.views import *
from queryset_sequence import QuerySetSequence
from dal.widgets import *
from dal.views import *
from dal_queryset_sequence.views import *
from dal_select2 import *
from dal_queryset_sequence import *

class Test(models.Model):

     name = models.CharField(max_length=200)

My settings.py:
INSTALLED_APPS = [
    'dal',
    'dal_select2',
    'dal_queryset_sequence',
    'django.contrib.admin'
...]

But the system throws out

AttributeError: module 'dal_select2.models' has no attribute 'Model'.

Tried to add "from dal_select2.models import Model or *", but not working.
Answer: This is exactly why you shouldn't use the from x import *. One of those modules you import - dal_select_2 - defines a name models, which overrides the one you actually wanted which is from django.db.
Only import the names you actually use, then this won't happen.
Answer: Add dal and dal_select2 to the INSTALLED_APPS


Form alteration is not working from within my form class

Question: I am following https://www.drupal.org/docs/8/api/form-api/introduction-to-form-api for my hello world module.
Below is my code
namespace Drupal\hello_world\Form;

use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;

/**
 * Implements an hello_world form.
 */
class HelloWorldForm extends FormBase {

    /**
     * {@inheritdoc}
     */
    public function getFormId() {
        return 'hello_world_form';
    }

    /**
     * {@inheritdoc}
     */
    public function buildForm(array $form, FormStateInterface $form_state) {

        $form['phone_number'] = array(
            '#type' => 'tel',
            '#title' => $this->t('Your phone number'),
        );
        $form['actions']['#type'] = 'actions';
        $form['actions']['submit'] = array(
            '#type' => 'submit',
            '#value' => $this->t('Save'),
            '#button_type' => 'primary',
        );
        return $form;
    }

    function hello_world_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
        if ($form_id == 'hello_world_form') {
            $form['phone_number']['#description'] = t('Start with + and your country code.');
        }
    }

}

I also cleated cache. Not sure why form is not altering.
Comment: This is not the proper way to do it. Procedural alter hooks can only go in .module files and some (like hook form alter) can also go in .theme files. They cannot reside in class files.
Comment: Also, for the record, you could add that description to the phone number field's `#definition` in your `buildForm()` method if you want!
Answer: Use your hello_world_form_alter in your module file. I guess should be hello_world.module. I guess you already have a folder hello_world where you placed the file above. In this folder you should also have an .info.yml file at the same folder place your hello_world.module file.
Please check https://www.drupal.org/docs/8/creating-custom-modules. You will find a lot of tutorials about how to create a custom module. Just google it!
Comment: How to use in module file? I'm NewBie
Comment: @Ankit I updated my answer. Have a look.
Comment: That I am following. I just need to know when I'm wrong or what needs to be done @Ismini
Comment: @Ankit At this tutorial there is also https://www.drupal.org/docs/8/creating-custom-modules/basic-structure which lets you know about the  files used in a module. As I said earlier, you need to place your hook (hello_world_form_alter) in he hello_wrold.module file. In your class you built the form and you use the hook_form_alter to alter the form which built in your class.
Answer: Remove function hello_world_form_alter from Form file & add
below code in hello_world.module
use Drupal\Core\Form\FormStateInterface;

/**
 * Implements hello_world_form_alter().
 */
function hello_world_form_alter(&$form, FormStateInterface $form_state, $form_id) {

  if ($form_id === 'hello_world_form') {
    $form['phone_number']['#description'] = t('Start with + and your country code. - Test');
  }
}


Problem related to a matrix

Question:
Taking $M$ to be of the form
\begin{pmatrix}
a &b  &c \\
d & e & f\\
 g& h & i
\end{pmatrix}  we get (from the $2$ given conditions) $6$ equations whereas total number of variables are $9$. So i think $(D)$ is the correct option.Am i going in the right direction? Please help.Thanks in advance for your time.
Answer: Hint: Is the vector $(6,0,0)^T$ a linear combination of the vectors $(1,2,3)^T$ and $(4,5,0)^T$? (For ease of  typing we are using $(x,y,z)^T$ for the column vector with entries $x$, $y$, and $z$.)
Remark: It is true that there are $9$ variables and only $6$ equations. But if the question had used, say, $(6,8,3)^T$ instead of $(6,0,0)^T$, the result would be determined. So simple counting of equations and unknowns is not enough.
Your suggested approach can be made to work, for example by exhibiting two solutions to the system of equations that give different results on $(6,0,0)^T$. This is equivalent to showing that the first column of the matrix $M$ is not determined.
Comment: Sir,I can not find the vector $(5,6,0)^T$ in the equations.Did you mean $(4,5,0)^T$?
Comment: @user53386: Thanks for noticing the typo. Corrected.
Answer: Yours way is correct. My way of thnking goes like this :
Since $$\pmatrix{6 \\ 0 \\ 0}=a \pmatrix{1 \\ 2 \\3}+b \pmatrix{4 \\ 5 \\0}$$ where such $a$ and $b$ do not exist, hence we cannot determine the matrix $M$
Comment: Your last $6$ was meant to be a zero?
Comment: @GerryMyerson: yeah , edited
Comment: @Idonknow thanks a lot.I have got it.+1 from me.

Problem related to a matrix


Legendre's formula for $n!$

Question: For what $n$ the following is true: $$\left[\dfrac{n}{5}\right]+\left[\dfrac{n}{5^2}\right]+\left[\dfrac{n}{5^3}\right]+\cdots=100$$
My sketch: We know that $[x]\leq x<[x]+1$ for any real $x$. Also its obvious that above sum is finite. We can estimate this sum: $$100\leq \dfrac{n}{5}+\dfrac{n}{5^2}+\cdots=\sum \limits_{k=1}^{\infty}\dfrac{n}{5^k}=n/4$$
Hence $n>400$.
I check this out on the computer and yielded that it's true for $n\in \{405, 406, 407, 408,409\}$. Why my estimate is wrong?
Comment: Why do you say your estimate wrong? It seems right enough.
Answer: Your estimate is not wrong. You estimated $n>400$. And it is true for $n=405, 406, 407, 408, 409$.
They all satisfy $n>400$.
Comment: Ok! But how to get the five numbers which satisfy above indentity?
Comment: Maybe my estimate is not wrong but it's too rough right?
Comment: @R.F.Z See the related question [here](http://math.stackexchange.com/questions/163388/given-number-of-trailing-zeros-in-n-find-out-the-possible-values-of-n).
Comment: @RFZ yeah. That is what it is.
Answer: Your estimate is not accurate because:
You should change this:
$$\color\red{100\leq\sum\limits_{k=1}^{\infty}\dfrac{n}{5^k}=n/4}$$
To this:
$$\color\green{100=\sum\limits_{k=1}^{\log_5n}\left\lfloor\dfrac{n}{5^k}\right\rfloor<\sum\limits_{k=1}^{\log_5n}\dfrac{n}{5^k}<\sum\limits_{k=1}^{\infty}\dfrac{n}{5^k}=n/4}$$

Keep in mind that we are dealing with positive integers here.
Therefore $k>\log_5n\implies5^k>n\implies\dfrac{n}{5^k}<1\implies\left\lfloor\dfrac{n}{5^k}\right\rfloor=0$.
Comment: I already meant this but I forgot mention it. Anyway your remark does not lead to a correct estimate. Am I right?
Comment: @RFZ: You are trying to find the minimum value of $n$ such that the multiplicity of $5$ in $n$ is $100$, right? The formula for that is $\sum\limits_{k=1}^{\log_5n}\left\lfloor\frac{n}{5^k}\right\rfloor$, not $\sum\limits_{k=1}^{\infty}\frac{n}{5^k}$.
Comment: @RFZ: No, it does not. It merely tries to explain why your estimate of $n=400$ is not accurate.
Comment: Thanks a lot! It became much better
Comment: @RFZ: You're welcome. I've expanded the explanation a little bit.
Comment: That's great! Thank you :)
Answer: From the initial estimate $n=400$, known to be a lower bound, write
$$\left[\dfrac{400+m}{5}\right]+\left[\dfrac{400+m}{5^2}\right]+\left[\dfrac{400+m}{5^3}\right]+\cdots=80+\left[\dfrac{m}{5}\right]+16+\left[\dfrac{m}{5^2}\right]+3+\left[\dfrac{25+m}{5^3}\right]+\left[\dfrac{400+m}{5^4}\right]++\left[\dfrac{400+m}{5^5}\right]+\cdots=100.$$
So you need
$$\left[\dfrac{m}{5}\right]+\left[\dfrac{m}{5^2}\right]+\left[\dfrac{25+m}{5^3}\right]+\left[\dfrac{400+m}{5^4}\right]+\left[\dfrac{400+m}{5^5}\right]+\cdots=1,$$
which is achieved for $\left[\dfrac m5\right]=1$, by inspection (for all $m$ such that $\left[\dfrac m5\right]\le1$, all terms but the first vanish).
Comment: You third term seems suspicious since $\left[\dfrac{400+m}{5^3}\right]=\left[\dfrac{375+25+m}{5^3}\right]=3+\left[\dfrac{25+m}{5^3}\right]$. Right?
Comment: Quite right, fixing. This doesn't change the conclusion. By the way, I am giving a complete solution.

Legendre's formula for $n!$


How can I make my brand new module dependent on a minimal core version that's required for it to work OK?

Question: I am developing a brand new module (there isn't any site using it yet). It requires a specific Drupal version, as it uses the hook_taxonomy_term_view() hook that was introduced in Drupal core version 7.17.
I want to avoid my module being enabled on a site using, for example, Drupal 7.16 or any earlier versions of Drupal core. Higher versions of Drupal, above 7.17, should be fine.
My Question: How can I make my module dependent on that Drupal 7.17 version, which is a minimum for my module?
Note: I don't need (have to worry about) a solution for sites where the module is already installed. So there is no need for it to be disabled somehow in such pre-7.17 Drupal versions.
Comment: The question is tagged [tag:hooks] because it is about a hook I should use in my code. [tag:hooks] doesn't mean I am looking for a hook I could use; I am open to any solution that allows me to avoid the module is installed on a site not using Drupal 7.17, or higher.
Comment: You can require a minor version of some other module by `dependencies[] = mymodule (1.12)` but it seems like this doesn't work for core.
Comment: @AyeshK Uh! Now, that could be interesting, if you could point me to a Drupal core module that is always enabled.
Comment: I tried it with `dependencies[] = taxonomy (>7.17)` and some other possible version numbers but didn't work.
Answer: The trick, apparently, is to add the System module as dependency for the module.
dependencies[] = system (>=7.17)

Comment: Yes, the trick is that. Given that the System module is always installed from Drupal, requiring it won't cause users to first install an optional module that isn't used from the module I am writing, as it would happen with `dependencies[] = taxonomy (>7.17)`.
Answer: hook_requirements() exists for exactly that sort of purpose.

Check installation requirements and do status reporting.

You can check the $phase parameter to determine if the module is being installed, check the current Drupal version against your required version, and return a severity of REQUIREMENT_ERROR. That will prevent the module from being installed until the requirement is met.
The documentation is pretty thorough, the one thing worth mentioning here is that the hook needs to be implemented in the module's .install file.
Comment: @Chapabu Not according to the docs :) It talks about modules specifically, and basically says to use that hook to return `REQUIREMENT_ERROR` to make sure a module is not installed if it fails the requirements. I'd assumed checking the version of Drupal was a valid use case (the docs don't mention _not_ doing that) but I guess I've missed something. It might just be bad practice or something I dunno
Comment: @Clive Weird, dunno where I got that from then..maybe D8 should just be a docs upgrade ;-)
Comment: @chx I'll take your word for it, but in that case the description of the function _"Check installation requirements and do status reporting."_ is somewhat misleading is it not? We are after all talking specifically about checking for module requirements upon installation :)
Comment: I always thought `hook_requirements` was meant for libraries etc. :-\
Comment: @Clive Just found this useful page [Contributor task: Backport a Drupal Core patch](http://drupal.org/node/1538380) - "*...if Drupal 8 is in progress, any bugs found in Drupal 6 or 7 need to be fixed first in Drupal 8, and then back-ported to Drupal 7*"
Comment: @Clive The [Backport policy](http://drupal.org/node/767608). seems pretty useful too!
Comment: Thanks @Chapabu I'd seen it but I wasn't sure if it applied to documentation. Coming from a C# background this open source stuff is pretty alien to me ;)
Comment: @Clive I looked into C# once.....looked right back away again ;-)
Comment: @Chapabu I miss it every day...;)
Answer: You could use the hook_enabled
This would fire after the module is installed. You can check the version of the drupal installed and if it is not the correct version then use module_disable and give the required error message.
Answer: With Drupal 8.x, it's still possible to add the System module as dependency of a module, to require a specific Drupal core version. Drupal 8.x uses YAML for the .info file (which now has a .info.yml extension), so the dependencies are declared with code similar to the following one.
dependencies:
  - drupal:serialization
  - drupal:system (>=8.2.x)

Since Drupal 8.8.0, it's possible to require a more specific Drupal core version using core_version_requirement.
core_version_requirement: ^8.8 || ^9

Using that line, which cannot be used together a line that sets core, the module is requiring at least Drupal 8.8.x or Drupal 9.x; any different Drupal version would mark the module as not compatible with the Drupal version used from the site.
As side note, the dependencies in Drupal 8 are namespaced. They require first the project machine name (for example, drupal for Drupal core) and then the module machine name (for example, system for the System module), separated from a colon. In this way, there isn't any ambiguity on which module is required.
Reference

Let Drupal know about your module with an .info.yml file


O que significa um "join table"?

Question: Eu estava lendo o livro Beginning Rails 4, quando me deparei com messe trecho na pagina 100.

Let's get back to the relationship between users and comments. You need to tell your user model that a user has many comments through its articles. Basically, you use the article model as a join table between users and comments. You achieve the linking using the has_many :through method.

O que significa esse conceito de join table ? Eu entendi no código o que ele faz, mas eu queria um conceito mais formal para isso.
Comment: Você sabe se o trecho se refere ao uso de `join table` em um SGBD?
Answer: Eu imagino que os modelos devem ser algo assim:
User:
  id
  username

Article:
  id
  user_id
  title
  text
Comment:
  id
  article_id
  text

Assim, um usuário tem muitos comentários pertencentes as suas perguntas, só que isso acontece através da tabela articles.
Na declaração seguinte você informa isso para o Rails:
class User
  has_many :articles
  has_many :comments, through: :articles
end

Imagine que você tem um objeto @user de id 99. Quando você usar @user.articles ele vai gerar um SQL assim:
SELECT *
FROM articles
WHERE user_id = 99

Não houve necessidade de JOIN.
Mas se você fizer @user.comments ele terá que fazer um JOIN:
SELECT comments.*
FROM comments
INNER JOIN articles
  ON comments.article_id = articles.id
WHERE articles.user_id = 99

Agora imagine que um comentário possa ter muitas respostas (replies):
class User
  has_many :articles
  has_many :comments, through: :articles
  has_many :replies, through: :comments
end

Ao fazer @user.replies ele fará dois JOINs:
SELECT replies.*
FROM replies
INNER JOIN comments
  ON replies.comment_id = comments.id
INNER JOIN articles
  ON comments.article_id = articles.id
WHERE articles.user_id = 99

Conclusão
Portanto, "join table" é quando exite esse relacionamento indireto entre tabelas.

O que significa um "join table"?


Running my python loop on a df and print responses in df

Question: I have a dataframe in Pandas:
In [10]: df
Out[10]:
                     Domain     Use
0        graph.facebook.com    4242
1            news.bbc.co.uk   23423
2  news.more.news.bbc.co.uk  234432
3       profile.username.co  235523
4           offers.o2.co.uk  235523
5     subdomain.pyspark.org    2325
6       uds.data.domain.net   23523
7         domain.akamai.net   23532

And I have a script which I can run against a single column of the dataframe: This works exactly as I want.
In [13]: for row in df.iterrows():
    ...:     cdns = ['akamai', 'maxcdn', 'cloudflare']
    ...:     tld = ['co.uk', 'com', 'org', 'co', 'net']
    ...:     index = df.Domain[df.Domain.str.strip().str.endswith(tuple(tld))].str.split('.').tolist()
    ...:
    ...: for x in index:
    ...:     if (x[len(x)-2]) in cdns:
    ...:         if str(x[len(x)-1]) in tld:
    ...:             print(str(x[len(x)-3])+'.'+str(x[len(x)-2])+'.'+ str(x[len(x)-1]))
    ...:     elif (x[len(x)-2]) in cdns:
    ...:         if str(x[len(x)-2]).rstrip()+'.'+ str(x[len(x)-1]).rstrip() in tld:
    ...:              print(str(x[len(x)-4])+'.'+ str(x[len(x)-3])+'.'+str(x[len(x)-2])+'.'+ str(x[len(x)-1]))
    ...:     elif str(x[len(x)-2]).rstrip()+'.'+ str(x[len(x)-1]).rstrip() in tld:
    ...:         print(str(x[len(x)-3])+'.'+str(x[len(x)-2])+'.'+ str(x[len(x)-1]))
    ...:     elif str(x[len(x)-1]) in tld:
    ...:          print(str(x[len(x)-2])+'.'+ str(x[len(x)-1]))

But, I need to add a new column to the dataframe with the result of my script as the contents. So I want to have the columns:
- DOMAIN
- USE
- NEW DOMAIN
Where newdomain = the result of my script.
How might I do that? I've searched high and low but no success
UPDATE
I've tried the below - but it adds the series called index to the column. I need the result of my for loop instead:
In [14]: df
Out[14]:
                     Domain     Use
0        graph.facebook.com    4242
1            news.bbc.co.uk   23423
2  news.more.news.bbc.co.uk  234432
3       profile.username.co  235523
4           offers.o2.co.uk  235523
5     subdomain.pyspark.org    2325
6       uds.data.domain.net   23523
7         domain.akamai.net   23532

In [15]: df['newdomain']=index

    In [16]: df
    Out[16]:
                         Domain     Use                        newdomain
    0        graph.facebook.com    4242           [graph, facebook, com]
1            news.bbc.co.uk   23423              [news, bbc, co, uk]
2  news.more.news.bbc.co.uk  234432  [news, more, news, bbc, co, uk]
3       profile.username.co  235523          [profile, username, co]
4           offers.o2.co.uk  235523             [offers, o2, co, uk]
5     subdomain.pyspark.org    2325        [subdomain, pyspark, org]
6       uds.data.domain.net   23523         [uds, data, domain, net]
7         domain.akamai.net   23532            [domain, akamai, net]

So the for loop will output : facebook.com, bbc.co.uk, etc.
Comment: `df['New Domain']=series_result` ?
Comment: Thanks for your reply, by doing that, i get the result ffrom index printed in the df - do you know how I can get the result of my for loop in there?
Comment: I don't know how your result looks like. Just post the relevant code here in which you are facing trouble. Add your final result here.
Comment: Just updated the description :-) thanks again
Comment: So what is the result of the loop?
Comment: The loop output is: facebook.com
bbc.co.uk
bbc.co.uk
username.co
o2.co.uk
pyspark.org
domain.net
net.domain.akamai.net
Comment: it'd the cleaned example of the domains (without sub domains)
Answer: This should solve the problem
import pandas as pd
df=pd.DataFrame({'Domain':[' graph.facebook.com','news.bbc.co.uk ']})
df['new_domain']=df.Domain.str.split('.',1, expand=True)[1] # split on '.' then take second element


Repeat symbol in the middle of the measure because of my lyrics and a starting rest

Question: I know what my problem is, just can't find how to solve it.
I have this (I hope) minimum example showing exactly what my problem is :
\version "2.18.2"
\language "italiano"

\score {
  \new ChoirStaff \relative do' <<

    \new Voice = "test" {
      R1
      \repeat volta 2 { si'4\rest }
          \alternative { { do } { do } }
    }

    \new lyrics = "test"

    \context Lyrics = "test" {
        \lyricsto "test" {
          \repeat volta 2 { te -- }
          \alternative { { st -- ing } { st -- er } }
        }
    }
  >>
}

Since my measure at the beginning of the repeat starts with a rest, two repeats are created, one for the melody, the other one for the lyrics. How can I delete the one corresponding to the lyrics ?
Answer: Create a hidden note in Voice = "test" to match the rhythm of the lyrics.
Then create another voice, containing just the rest.
Note, you need to explicitly create a staff for the two voices, otherwise you get two separate staves within the ChoirStaff.
I deleted \new lyrics = "test" which produces a warning message
\version "2.18.2"
\language "italiano"

\score {
  \new ChoirStaff \relative do' <<

    \new Staff <<
      \new Voice = "test" {
        R1
        \repeat volta 2 { \hideNotes si'4 \unHideNotes }
            \alternative { { do } { do } }
      }
      \new Voice {
        s1
        \repeat volta 2 { si4\rest }
            \alternative { { s4 } { s4 } }
      }
    >>

    \context Lyrics = "test" {
        \lyricsto "test" {
          \repeat volta 2 { te -- }
          \alternative { { st -- ing } { st -- er } }
        }
    }
  >>
}


Apache2 and redundant LDAP configuration Problems

Question: According to instructions, I have configured multiple LDAP sources for redundancy.  I have found some problems with the configuration.

If an ldap service is not working on the designated ldap server instead of going
to the next server in the list, work does not progress through the other entries in the list things just hang.
If an ldap server is down and not working,  it throws a 5xx internal server error does not progress through the other entries in the list.

Are these apache bugs or should I be including more directives to properly configure the redundancy?
Section of http.conf in question:
<code> <AuthnProviderAlias ldap ldap1>
     AuthBasicProvider ldap
     AuthLDAPURL "ldap://ldap1.server.com:389/dc=server,dc=com?sAMAccountName?sub?(objectClass=*)"
     AuthLDAPBindDN "CN=matcher,OU=Application Accounts,dc=server,dc=com"
     AuthLDAPBindPassword "SECRET"
 </AuthnProviderAlias>

 <AuthnProviderAlias ldap ldap2>
     AuthBasicProvider ldap
     AuthLDAPURL "ldap://ldap2.server.com:389/dc=server,dc=com?sAMAccountName?sub?(objectClass=*)"
     AuthLDAPBindDN "CN=matcher,OU=Application Accounts,dc=server,dc=com"
     AuthLDAPBindPassword "SECRET"
 </AuthnProviderAlias>

 <AuthnProviderAlias ldap ldap3>
     AuthBasicProvider ldap
     AuthLDAPURL "ldap://ldap3.server.com:389/dc=server,dc=com?sAMAccountName?sub?(objectClass=*)"
     AuthLDAPBindDN "CN=matcher,OU=Application Accounts,dc=server,dc=com"
     AuthLDAPBindPassword "SECRET"
 </AuthnProviderAlias>

 <AuthnProviderAlias file file1>
         AuthUserFile /etc/mdpctest/htpasswd.users
 </AuthnProviderAlias>

 <Directory /srv/www/htdocs/mdptest>
 Order deny,allow
 Deny from All
 AuthName "Request Access"
 AuthType Basic
 AuthBasicProvider file1 ldap1 ldap2 ldap3
 AuthzLDAPAuthoritative on
 require valid-user
 Satisfy any
 </Directory>
</code>
The Apache Versioning information is:
<code> Server version: Apache/2.2.12 (Linux/SUSE)
 Server built:   Nov 30 2011 17:54:13
 Server's Module Magic Number: 20051115:23
 Server loaded:  APR 1.3.3, APR-Util 1.3.4
 Compiled using: APR 1.3.3, APR-Util 1.3.4
 Architecture:   64-bit
 Server MPM:     Prefork
   threaded:     no
     forked:     yes (variable process count)
 Server compiled with....
  -D APACHE_MPM_DIR="server/mpm/prefork"
  -D APR_HAS_SENDFILE
  -D APR_HAS_MMAP
  -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
  -D APR_USE_SYSVSEM_SERIALIZE
  -D APR_USE_PTHREAD_SERIALIZE
  -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
  -D APR_HAS_OTHER_CHILD
  -D AP_HAVE_RELIABLE_PIPED_LOGS
  -D DYNAMIC_MODULE_LIMIT=128
  -D HTTPD_ROOT="/srv/www"
  -D SUEXEC_BIN="/usr/sbin/suexec2"
  -D DEFAULT_PIDLOG="/var/run/httpd2.pid"
  -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
  -D DEFAULT_LOCKFILE="/var/run/accept.lock"
  -D DEFAULT_ERRORLOG="/var/log/apache2/error_log"
  -D AP_TYPES_CONFIG_FILE="/etc/apache2/mime.types"
  -D SERVER_CONFIG_FILE="/etc/apache2/httpd.conf"
</code>
Comment: Have tried AuthzLDAPAuthoritative on both in the off and on position with no effect.
Answer: Well this has worked for me:
<code>AuthLDAPURL ldap://ldap.company.com:389,ldapbackup.company.com:1389/ou=Users,dc=company,dc=com?uid
</code>
I didn't need any quotes and separating the servers with a space didn't work. (Apache/2.2.14)
Comment: I'm wondering if the QUOTES are necessary since there is a space between the parameters.  (The format comes from the Apache website).  Also, wondering if some smart programmer put in the parse for the COMMA character realizing the problem with the SPACE in the first place?
Comment: Hehe it may be so, but I didn't check the source.
Answer: The answer is specify the multiple source in the LDAP configuration record.
Notice the space separating the host specs in the AuthLDAPURL as well as the fact that the directive is enclosed in quotes:
Section of http.conf in question:
<code> <AuthnProviderAlias ldap ldap1>
     AuthBasicProvider ldap
     AuthLDAPURL "ldap://ldap1.server.com:389 ldap2.server.com:389 ldap3.server.com:389/dc=server,dc=com?sAMAccountName?sub?(objectClass=*)"
     AuthLDAPBindDN "CN=matcher,OU=Application Accounts,dc=server,dc=com"
     AuthLDAPBindPassword "SECRET"
 </AuthnProviderAlias>

 <AuthnProviderAlias file file1>
         AuthUserFile /etc/mdpctest/htpasswd.users
 </AuthnProviderAlias>

 <Directory /srv/www/htdocs/mdptest>
 Order deny,allow
 Deny from All
 AuthName "Request Access"
 AuthType Basic
 AuthBasicProvider file1 ldap1
 AuthzLDAPAuthoritative on
 require valid-user
 Satisfy any
 </Directory>
</code>


What does $\doteqdot$ mean?

Question: I am reading the following document of Solitary waves page $14$. And I found the following symbol $\doteqdot$.
What does  $\doteqdot$ mean? For example:
$$y_t \doteqdot -c_0y_x $$
Comment: The relevant information might already be here, but I think that that page you linked is behind a paywall.
Comment: This is Unicode 2251, called "GEOMETRICALLY EQUAL TO".
Comment: @Somos You could post that as an answer
Answer: After the very first equation (1.1) is this line

breaking occurs for a≑d. ...

so I think that it means "approximately equal to" which is usually written with ≈. I don't know why the author decided to use this symbol. It must
be a rare usage because I had not seen it used before.
Answer: Search "Geometrically equal to" on this page
https://www.w3.org/TR/MathML2/isoamsr.html
I don't know what that means, but it's the right symbol.
Comment: It means same size and shape.
Comment: Is that congruent?
Comment: Compare to the similar symbol in the codepoint below that one. I'm pretty sure Somos's comment was right that the meaning here is "approximately equal to" and not "geometrically equal to" (whatever that was intended to mean). In general, the Unicode glosses are not a good reference for all usages of a symbol.

What does $\doteqdot$ mean?


anova.gam, significant test and 0 deviance?

Question: I have fitted a series of GAMs of increasing complexity, and compared with anova.gam. I get a significant p value (based on Chisq test) for a pair of models, even though the difference in deviance between the two models is 0.
The models are specified using default settings for gam, in mgcv (i.e. select = FALSE).
The smooth term in model 2 is non-significant and has edf = approx. 0, p = 1. Therefore I am not surprised the deviance does not change with its inclusion. However, I would expect the p value for the Chisq test to be ~1.
Am I misinterpreting this test?
Output below. Note the p-value for contrast between models 1 and 2 is very small even though deviance is 0.
anova.gam(model1, model2, models3, test="Chisq")
Analysis of Deviance Table

Model 1: outcome ~ s(sujetno, bs = "re")
Model 2: outcome ~ s(z.Cluster_1_PC1) + s(sujetno, bs = "re")
Model 3: outcome ~ s(z.Cluster_1_PC1) + s(sujetno, bs = "re") + z.age

  Resid. Df Resid. Dev          Df Deviance  Pr(>Chi)
1      1890     1889.0
2      1890     1889.0 -4.8263e-08    0.000 4.707e-07 ***
3      1886     1878.2  4.0115e+00   10.765   0.02899 *

Answer: In the wikipedia-definition of the $\chi^2$-distribution (https://en.wikipedia.org/wiki/Chi-squared_distribution), $k$ (the "degrees of freedom") is an integer. However, the distribution itself can be evaluated for non-integer values, too.
In your case, your change in deviance is tiny (the value is not actually shown, except that it is less than 0.001), but the difference in degrees of freedom is even tinier. Hence, when computing the resulting $\chi^2$-value, it becomes highly significant. To illustrate:
dchisq(0.001, df=1E-8)
[1] 4.9975e-06

Now, on the help-page for "step.gam" mgcv-author Simon Wood suggests shrinkage/penalisation rather than model comparison. I guess your situation is a case in point.


krakend lua scripting fail by load lib

Question:  "endpoint": "/apps/{id}",
      "output_encoding": "no-op",
      "method": "GET",
      "backend": [
        {
          "host": [
            "http://xxx.yyy.zz:8888"
          ],
          "url_pattern": "/apps/{id}",
          "extra_config": {
            "modifier/lua-backend": {
              "sources": [
                "/etc/krakend/Hello.lua"
              ],
              "post": "local r = response.load(); printPostBody(r:body());",
              "allow_open_libs": true
            }
          }
        }
      ]
    },

My Hello.lua:
local mylua = require("cjson")

function printPostBody(body)
    print(body);
end

When i add this part: local mylua = require("cjson") i got this error:
2023/10/08 09:36:23 [Recovery] 2023/10/08 - 09:36:23 panic recovered:
runtime error: slice bounds out of range [-1:]
/usr/local/go/src/runtime/panic.go:153 (0xf3dc7e)
/email@example.com/error.go:140 (0x1971f64)
/firstname.lastname@example.com/binder.go:27 (0x1970866)
/firstname.lastname@example.com/error.go:201 (0x1972397)
/email@example.com/binder.go:43 (0x19707ee)
/email@example.com/binder.go:26 (0x1970785)
/email@example.com/proxy/proxy.go:75 (0x1979793)
/firstname.lastname@example.com/proxy/balancing.go:77 (0x13080a8)
/email@example.com/proxy/http.go:113 (0x130db84)
/email@example.com/router/gin/endpoint.go:50 (0x1bbf674)
/email@example.com/context.go:174 (0x1bb49c1)
/firstname.lastname@example.com/recovery.go:102 (0x1bb49ac)
/email@example.com/context.go:174 (0x1bb3ae6)
/firstname.lastname@example.com/logger.go:240 (0x1bb3ac9)
/email@example.com/context.go:174 (0x1bb296a)
/email@example.com/gin.go:620 (0x1bb25f1)
/email@example.com/gin.go:576 (0x1bb211c)
/usr/local/go/src/net/http/server.go:2936 (0x128a0b5)
/usr/local/go/src/net/http/server.go:1995 (0x1285251)
/usr/local/go/src/runtime/asm_amd64.s:1598 (0xf761a0)

Answer: As you have seen, if you remove the line with a require that will work. The thing with Lua in KrakenD is that is not a regular Lua engine, but kind of a virtual machine that is restricted to the standard library and has no dependency injection. You cannot use Lua Rocks neither import anything that is not under the sources directory.
So you cannot import Lua libraries like this (require). If you want to include JSON parsing libraries you will need to import them by hand under sources.

krakend lua scripting fail by load lib


Gerar todas as trocas de letras possíveis em uma palavra

Question: Preciso criar uma função que gere todas as possiveis trocas de letras que gerem palavras com o mesmo som:
Palavra: Feijoada
Possibilidades: Feigoada, Feyjoada, Feijoada, Feygoada

Porém não estou conseguindo fazer isso, minha função retorna apenas uma palavra:
Feigoada

Código:
word = input()
word = word.lower()
cont = 0

letterlist = []
wordslist = []

for letter in word:
    letterlist.append(letter)
while cont < 6:
    if "c" not in letterlist:
        pass
    else:
        word2 = ""
        for letter in word:
            if letter == "c":
                letter = "k"
                word2 = word2+letter
            else:
                word2 = word2+letter
        if word2 in wordslist:
            pass
        else:
            wordslist.append(word2)

    if "k" not in letterlist:
        pass
    else:
        word2 = ""
        for letter in word:
            if letter == "k":
                letter = "c"
                word2 = word2+letter
            else:
                word2 = word2+letter
        if word2 in wordslist:
            pass
        else:
            wordslist.append(word2)

    if "m" not in letterlist:
        pass
    else:
        word2 = ""
        for letter in word:
            if letter == "m":
                letter = "n"
                word2 = word2+letter
            else:
                word2 = word2+letter
        if word2 in wordslist:
            pass
        else:
            wordslist.append(word2)

    if "n" not in letterlist:
        pass
    else:
        word2 = ""
        for letter in word:
            if letter == "n":
                letter = "m"
                word2 = word2+letter
            else:
                word2 = word2+letter
        if word2 in wordslist:
            pass
        else:
            wordslist.append(word2)

    if "j" not in letterlist:
        pass
    else:
        word2 = ""
        for letter in word:
            if letter == "j":
                letter = "g"
                word2 = word2+letter
            else:
                word2 = word2+letter
        if word2 in wordslist:
            pass
        else:
            wordslist.append(word2)

    if "g" not in letterlist:
        pass
    else:
        word2 = ""
        for letter in word:
            if letter == "g":
                letter = "j"
                word2 = word2+letter
            else:
                word2 = word2+letter
        if word2 in wordslist:
            pass
        else:
            wordslist.append(word2)
    cont += 1

O que posso estar errando nesse código? Existe alguma biblioteca que já faça esse trabalho?
Comment: 'Feijoada' e 'Feigoada' nao possuem o mesmo som..
Essa troca de J por G deve ser implementada apenas caso a letra venha antes de  'e' ou 'i', não?
Comment: Eu tinha feito só com algumas letras inicialmente. Não tinha parado para pensar a respeito certinho do G e J. Muito obrigado pela dica!
Answer:
No código existem apenas os tratamentos para as letras (C e K), (M e N) e (J e G).
Não existe o tratamento para (I e Y) por exemplo. Precisa criá-lo.
Outro detalhes, nao pode trocar o J pelo G em todas as palavras.. apenas as que tenham e ou i após a letra... Feijoada nao tem o mesmo som de Feigoada.


Apagar texto no campo de EditText

Question: Como eu faço para apagar um texto depois do envio.
<code>    enviar.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            String value = editText.getText().toString();

            //push creates a unique id in database
            demoRef.push().setValue(value);

            Toast.makeText(TelaPolicia.this,
                    "Enviando", Toast.LENGTH_LONG).show();

        }
    });
</code>

<code>    <EditText
        android:id="@+id/editescrever"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/btnenviar"
        android:layout_alignParentStart="true"
        android:layout_marginBottom="31dp"
        android:layout_marginStart="19dp"
        android:ems="10"
        android:hint="Escreva o incidente"
        android:inputType="textPersonName"
        android:textSize="18sp" />

    <Button
        android:id="@+id/btnenviar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="123dp"
        android:text="Enviar" />
</code>
Comment: editText.setText("");
Comment: `editText.setText("");` é a resposta certa, não entendi porque o @AntonioS.Junior colocou como comentário.
Comment: Vou colocar como resposta, foi mal!
Answer: Defina seu EditText com o valor que você quiser após a sua ação de enviar. No seu caso seria:
<code>editText.setText("");
</code>

Apagar texto no campo de EditText


Permissions error with Google Analytics API and VB.net

Question: Here's what I'm trying to do: I'm trying to generate an access token on the server side that will serve to authenticate a user as in this example:
https://ga-dev-tools.appspot.com/embed-api/server-side-authorization/
I've written this code in VB.net after several tries:
Public GA_Token As String

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    Dim filename As String = {{path to p12 file}}
    Dim serviceAccountEmail As String = {{service account generated email from IAM & Admin from console.developers.google.com of the form user@project name.iam.gserviceaccount.com}}
    Dim certificate = New X509Certificate2(filename, "password", X509KeyStorageFlags.Exportable Or X509KeyStorageFlags.MachineKeySet Or X509KeyStorageFlags.PersistKeySet)
    Dim Scopes As IEnumerable(Of String) = {AnalyticsService.Scope.AnalyticsReadonly}
    Dim credential As New ServiceAccountCredential(New ServiceAccountCredential.Initializer(serviceAccountEmail) With {.Scopes = Scopes}.FromCertificate(certificate))
    GA_Token = credential.GetAccessTokenForRequestAsync(Request.Url.ToString, CancellationToken.None).Result

End Sub

GA_Token is then written to the Analytics page I created.
The problem is that, when I go to view the reports, I get a 403 error from Chrome.
Objectbody: "{"error":{"errors":[{"domain":"global","reason":"insufficientPermissions","message":"User does not have any Google Analytics account."}],"code":403,"message":"User does not have any Google Analytics account."}}"headers: Objectcache-control: "private, max-age=0"content-encoding: "gzip"content-length: "146"content-type: "application/json; charset=UTF-8"date: "Fri, 18 Nov 2016 18:25:08 GMT"expires: "Fri, 18 Nov 2016 18:25:08 GMT"server: "GSE"vary: "Origin, X-Origin"www-authenticate: "Bearer realm="https://accounts.google.com/", error=insufficient_scope, scope="https://www.googleapis.com/auth/analytics.edit""proto: Object__defineGetter__: defineGetter()defineSetter: defineSetter()lookupGetter: lookupGetter()lookupSetter: lookupSetter()constructor: Object()hasOwnProperty: hasOwnProperty()isPrototypeOf: isPrototypeOf()propertyIsEnumerable: propertyIsEnumerable()toLocaleString: toLocaleString()toString: toString()valueOf: valueOf()get proto: proto()set proto: proto()result: Objecterror: Objectcode: 403errors: Array[1]0: Objectlength: 1__proto__: Array[0]message: "User does not have any Google Analytics account."proto: Object__proto__: Objectstatus: 403statusText: null__proto__: Object_.nH @ cb=gapi.loaded_0:606_.du.Vh @ cb=gapi.loaded_0:742(anonymous function) @ view-selector2.js:109h.o0 @ cb=gapi.loaded_0:75xs @ cb=gapi.loaded_0:78Wq @ cb=gapi.loaded_0:78_.C.uea @ cb=gapi.loaded_0:77Ap @ cb=gapi.loaded_0:71
cb=gapi.loaded_0:67 Uncaught Object {result: Object, body: "{"error":{"errors":[{"domain":"global","reason":"i…er does not have any Google Analytics account."}}", headers: Object, status: 403, statusText: null}(anonymous function) @ cb=gapi.loaded_0:67
Now, I can use the OAuth2 protocol to generate the token and have it display if the user logs in to his/her account, but I'm trying to bypass that. The problem I'm running into is that I don't see where I'm supposed to set the permissions for the account. I went into IAM and Admin and enabled Domain-wide Delegation on two different service accounts to test with. I set them with every permission imaginable (which worked out to Owner + 18 other permissions). Where else do I need to set permissions, or am I overlooking something?
Comment: Wow 16 upvotes, 1 downvote... thats the lowest I've ever seen!
Comment: I'm sorry, but I don't see any upvotes or downvotes. Was this for me?
Answer: First, set the User email like this here, not sure how to do that in VB.
You say:

I can use the OAuth2 protocol to generate the token and have it display if the user logs in to his/her account, but I'm trying to bypass that.

But I see that you're also trying to use a Google Service Account, which I think only works if you are a paying G Suite user.
I've spent a lot of time to figure this out for my Gmail client and by accident found the solution:
The permissions should be visible per user under Connected Apps.
But this does mean however that your user has to manually grant access once, after that you can just get a token using the Google Service Account.
Comment: FWIW, I'm not a paying G suite user.
Comment: I gave the bounty to Kape because it was the user property answer he posted in another thread that solved my issue.
Comment: I've updated my answer, I had both issues but maybe because you're using another Google service the second part isn't an issue in your case.
Answer: The issue is explained on the Json
"{"error":{"errors":[{"domain":"global","reason":"insufficientPermissions","message":"User does not have any Google Analytics account."}]

{ "User does not have any Google Analytics account." }

Maybe change the code will not change anything, because it's an access error.
In a few words, You gmail used to get the Token has no account linked.
The validation process for the Auth look wells. Before change code i recommend you do the following steps.
1.- Get a valid Email and Passwords
I can believe you already got this (you already have the toke), grab this credentials and go to
https://analytics.google.com/analytics/web/ , login with these credential and And see if you have any account linked.
If you account have no access you will see

Note: If you use the Oauth validate, the email used to get the token can be different that the one used on the project, maybe you need to use someone else's credentials. Be 100% sure of what credential are you using.
2.- If you have no account you need to ask access, so the user with the Google Analytics Account needs to give you access. In  the desired account you need to go Admin -> User Management , and add the email used on the Validation Process:

When you have you token, remember store it and refresh it whenever you need, the tokens needs to be mananged
3.- If you want to get your own data, maybe you can use a P12key, as Jeremy says, this method is more easy to validate, but you need to add the p12key on every query (usually the library does it for you).  But with this method you can only access to data linked to your own gmail account. If you change the method you can have the same error, that it the need to be 100% of the used account
Answer: I tried and it works for me.
I had previously setup a Project called "YYYassistant" and I created an account:

Then I created a simple WinForm app and could not reproduce the issue, this works:
Imports Google.Apis.Auth.OAuth2
Imports System.Security.Cryptography.X509Certificates

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim scopes As String() = New String() {AnalyticsService.Scope.Analytics}
        ' view and manage your Google Analytics data
        Dim keyFilePath = "C:\Temp\YYYassistant-1234db98765.p12"
        ' Downloaded from https://console.developers.google.com
        Dim serviceAccountEmail = "email@example.com"
        ' found https://console.developers.google.com
        'loading the Key file
        Dim certificate = New X509Certificate2(keyFilePath, "notasecret", X509KeyStorageFlags.Exportable)
        Dim credential = New ServiceAccountCredential(New ServiceAccountCredential.Initializer(serviceAccountEmail) With {.Scopes = scopes}.FromCertificate(certificate))
    End Sub
End Class

"code":403,"message":"User does not have any Google Analytics account."

Its a problem with your account, make a new one.


Need help understanding how C hyperparameter influences $w $ in regularized SVM

Question: I am following Andrew Ng's lecture notes on SVM from CS229.
What I am having trouble understanding is the new objective function.
$min_{γ,w,b} \frac{1}{2} ||w||^2 + C\sum_{i = 1}^{m}ξ_i$
From what I understand, if we increase C to have really high value, the objective function will be large, and to compensate for that w need to be small. Now we know that reducing w results in the larger margin and vice versa. Therefore, in this case the margin should be large, but it isn't. For high values of C, the margin is small and its a Hard margin classification.
Similarly, for smaller values of C, it becomes a soft margin classification.
I don't understand how the C influences the value of w and maybe I am missing something here.
I'd really appreciate if someone can give me a clear and intuitive understanding of how w, C and the concept of margin are interrelated to each other.
Thanks.
Answer: The best way to understand the role of the hyperparameter $C$ is to think in term of robustness of your classifier. In short, $C$ is the hyperparameter that you will have to tune to find the optimal trade off between two competing objectives, which are 1) to make sure that your classifier performs well on your training data and 2) that it will also generalize well on unseen data.
Let's assume that you begin by training a "classical" SVM (i.e. without the regularization terms $C$ and $\xi_i$). If your training data set is well behaved (i.e. without outliers and linearly separable), then end result should look like this:

with the solid line being the classifier. However, if you train the same kind of SVM on a data set containing outliers, the result will be the following:

Here, the red point is an outlier, and using the unregularized objective function will lead to the classifier drawn as a solid line (instead of the expected classifier represented by a dashed line that we would have obtained, had we not considered the outlier). The classifier performs well on your training set (since all data points are correctly classified), but will poorly generalize on new data points (any new point falling into the blue area will be missclassified). This classifier is said to overfit or to lack robustness.
One way to avid this pitfall is to modify your objective function so as to allow some of your training points to be missclassified (i.e. to have a margin of $1-\xi_i$ instead of $1$). But we don't want too many of these points to be missclassified (otherwise the whole point of training a SVM to perform classification disappears). We thus have two competing objectives:

On the one hand, like in the classical case, we want the $\xi_i$ not to be too high, to make sure the boundary is violated as little as possible. This is represented by adding the $\sum_i \xi_i$ term in the objective function;
On the other hand, we also want to ensure the robustness of the classifier. The constraints are thus relaxed and become $y^{(i)}(w^T x^{(i)} + b) \geq 1-\xi_i$ instead of $y^{(i)}(w^T x^{(i)} + b) \geq 1$.

The hyperparameter $C$ determines how much you care about the respective objectives. If you set $C$ to be very high, then the only way to minimize your objective function will be to set all the $\xi_i$ to $0$. You are thus back to the original case in which the constraints are not relaxed. In contrary, if you care about the robustness of your classifier, you should set $C$ to a small value (to allow the $\xi_i$ to take whichever values they want).
Finding the optimal value for $C$ can be done by performing cross validation. If you obtain a very low training error, but a high test error (which is a telling sign of overfitting), you should consider increasing the value of $C$ and redo the whole tuning.
Even if you know a priori that your data set is linearly separable, adding the regularization terms $\xi_i$ is still a good idea, as it will allow your classifier to generalize well in case of outliers.
Comment: To be exact : if $C$ becomes large (infinite $C$ is a degenerate case), then the $\xi_i$ should indeed be close to 0, and the classifier will indeed try to correctly classify the outliers. By doing so, the margin becomes very narrow (look at how close some points are from the solid line in the second picture). If $C$ becomes small ($C = 0$ is a degenerate case) then the classifier allows some outliers to be misclassified. Some points will thus have a functional margin smaller than 1. The 'road' is simply built so as to minimize the cost function, nothing else.
Comment: So let me try to understand with an example. Suppose $C$ is infinite. In that case, the $ξ_i$'s should be zero in order to minimize the objective, in doing so, the functional margin for those become $y^{(i)}(w^T x^{(i)} + b) = 1$ and we are taking the outliers into consideration. As a result, our margin has to let these outliers position on the gutters of the large margin, and so the road becomes so narrow to accomodate them. While, if $C = 0$, its as if the outliers don't exist, and we only build the road wrt the points who has f. margin = 1, thus a wider road. Am I right?
Comment: Let us know if you have further questions or need more explanation. If this answer or any other one solved your issue, please mark it as accepted :)


Five a side tournament - awarding bye's in a partial round robin

Question: I help to run a five-a-side tournament with my scout group; we tend to have around 40 teams which split across 4 age groups. We can't run full round-robins at the group stage, so instead we run 4 games for each team, award points and put the best teams through to a knockout round.
The fixtures are all pre-arranged the day before, so if a team doesn't show up on the day it's sometimes not possible to avoid the situation where a bye has to be awarded to some of the teams.
In this situation, what's the correct score to award? We award 3 points for a win, 2 for a score draw and 1 for nil-nil. In practice goal difference often decides who goes through to the knockouts.
FWIW my own answer would probably be to award a score draw, which might avoid introducing an unfair advantage without penalising the team for missing a game?
Answer: There is no simple answer to this - you can probably make a reasonable case for any result apart from a loss. If this is causing a big problem for your tournaments, you probably need to rethink the tournament structure - have you considered e.g. running pools for the first but of the tournament, so the effect is limited to just that pool, rather than affecting the whole age bracket?
Comment: Thanks Philip, after running this thing for 4 years I'm still feeling like a novice! We do do this when possible, so we'll usually have (depending on the number of entries) one or two groups of between 4 and 7 teams each. We then draw them against each other randomly in 4 games. We run the whole tournament in one day on 6 pitches so we could never run a full round robin!
Comment: If you can mange two pools of 7 = 14 teams, you're playing (14 * 4) / 2 = 28 games. With that, you can do a full round robin for up to 8 teams - after that split into two pools. At 12 teams, split into three pools of 4. The numbers will vary a bit according to how many gangs you can actually manage, but things always get much easier if you can actually do round-robin.
Comment: Philip is right, in this case you could just allow a 3-0 win for each team for the game against the not showing up team :) And it depends on the game length too


PKG with Axios 1.x can't be compiled

Question: I tried so many things but with 0 efficiency. I made my Node.js app which contains some API requests that I managed with axios, but I can't make it into an exe file. I tried to downgrade the Axios version on 0.27.0 and it work, but I need to use the version 1.15 because I'm using HTTP/s-proxy-agent and on the lower versions, before 1.x doesn't work.
Here is the warnings I got from pkg when I try to build my project.
> Warning Failed to make bytecode node18-x64 for file /snapshot/ValorantCheckerJs/node_modules/axios/index.js
> Warning Failed to make bytecode node18-x64 for file /snapshot/ValorantCheckerJs/node_modules/axios/lib/axios.js
> Warning Failed to make bytecode node18-x64 for file /snapshot/ValorantCheckerJs/node_modules/axios/lib/utils.js
> Warning Failed to make bytecode node18-x64 for file /snapshot/ValorantCheckerJs/node_modules/axios/lib/helpers/bind.js
> Warning Failed to make bytecode node18-x64 for file /snapshot/ValorantCheckerJs/node_modules/axios/lib/core/Axios.js
> Warning Failed to make bytecode node18-x64 for file /snapshot/ValorantCheckerJs/node_modules/axios/lib/core/mergeConfig.js
> Warning Failed to make bytecode node18-x64 for file /snapshot/ValorantCheckerJs/node_modules/axios/lib/defaults/index.js
> Warning Failed to make bytecode node18-x64 for file /snapshot/ValorantCheckerJs/node_modules/axios/lib/helpers/formDataToJSON.js
> Warning Failed to make bytecode node18-x64 for file /snapshot/ValorantCheckerJs/node_modules/axios/lib/cancel/CanceledError.js
> Warning Failed to make bytecode node18-x64 for file /snapshot/ValorantCheckerJs/node_modules/axios/lib/cancel/CancelToken.js
> Warning Failed to make bytecode node18-x64 for file /snapshot/ValorantCheckerJs/node_modules/axios/lib/cancel/isCancel.js
> Warning Failed to make bytecode node18-x64 for file /snapshot/ValorantCheckerJs/node_modules/axios/lib/env/data.js
> Warning Failed to make bytecode node18-x64 for file /snapshot/ValorantCheckerJs/node_modules/axios/lib/helpers/toFormData.js

Here is my package.json file, i tryied to make some configs for pkg but without any effect.
"pkg": {
    "outputPath": "./dist",
    "targets": [
      "win"
    ],
    "assets": [
      "./node_modules/axios/dist/node/axios.cjs"
    ]
  },
  "dependencies": {
    "axios": "^1.5.0",
    "child_process": "^1.0.2",
    "colors": "^1.4.0",
    "http": "^0.0.1-security",
    "http-cookie-agent": "^5.0.4",
    "http-proxy-agent": "^7.0.0",
    "https-proxy-agent": "^7.0.1",
    "jsonwebtoken": "^9.0.1",
    "prompt-sync": "^4.2.0",
    "socket.io": "^4.7.2"
  },

By the way, I already try to change the requests library with node-fetch but when I build it, it doesn't execute that line. It's just simply closes it.
Answer: if you want to make you life easier and not have to handle all of this stuff. you need to take all of your code and create one single js file which include all of your app code with no fancy js stuff like import etc.
for example in your case lets say you code is in server/app.js
first step
install ncc with npm i -g @vercel/ncc (please note I installed this globally but of course you can install it localy and enter the following command in "commands" section in package.json. and of course you can use any tool like ncc)
second step
generate one js file for you server by running the command ncc build server/app.js
third step
now you should have the following file dist/index.js which includes all the app code in one file. now run pkg on this file for example pkg --targets win32 dist/index.js now its should compile without problem and include axios in it
Comment: Thanks man, that works really well. I dont have words to thank you.

PKG with Axios 1.x can't be compiled


Why matplotlib has no attribute 'pylab'?

Question: I imported matplotlib in the way like this:
import matplotlib as mpl

A error saying 'module' object has no attribute 'pylab' was thrown out when i run the following code:
x = np.arange(0,10,0.01)   # import numpy as np
y = np.sin(x)
mpl.pylab.plot(x,y)
mpl.pylab.show()

And there was no error appears when i imported  matplotlib in another way:
import matplotlib.pylab as pl

Is there anybody knows what happend?
Answer: To plot in non-interactive mode, you should use the module pyplot, not pylab.
from matplotlib import pyplot
import numpy

pyplot.plot(range(1,100), numpy.sin(range(1,100)))
pyplot.show()

The module pylab is not typically used as a submodule of matplotlib, but as a top-level module instead. Typically, it is used in interactive mode to bring together several parts of numpy, scipy and matplotlib into one namespace.
>>> from pylab import *
>>> plot(range(1,100), sin(range(1,100)))
>>> show()

Comment: I care nothing but how to use **pylab** or **pyplot** correctly! BUT what you mentioned it's a good advice to me.
Comment: @ Chinmay: `from pyplot import *` has to be pylab, I think
Answer: Submodules are not always imported by default.  You can import pylab with
import matplotlib as mpl
import matplotlib.pylab  # Loads the pylab submodule as well
# mpl.pylab is now defined

This is why doing import matplotlib.pylab as pl solved the problem, for you.
Not importing submodules by default brings faster loading times.  It also does not pollute the main module namespace with unused submodule names.  The creator of a module can define which submodules are loaded by default (since pylab is quite heavy, it is not imported by default by matplotlib).
Answer: You normally get this error if the module you are trying to import does not have a __init__.py file.  I also get this error on my installation.  I think you just have to accept that you must import matplotlib.pylab separately from matplotlib.
Comment: Which submodules are imported by default is actually under the full control of the module creator.  In the case of `pylab`, `matplotlib/__init__.py` could in fact include a simple `import pylab` and `matplotlib.pylab` would be made available through `import matplotlib` (there is no need for it to have an `__init__.py` file).


CameraBridgeViewBase get all supported resolution Android

Question: I have an app which needs to know all the camera supported resolutions - how do i access that data?
any suggestions?
Comment: I think this is what you're looking for http://stackoverflow.com/questions/5934829/how-to-get-supported-video-camera-resolutions-in-android
Comment: Thank you but thats not it,It cant be applied to camerabridgeviewbase
Answer: import static android.hardware.Camera
import org.opencv.android.CameraBridgeViewBase;

I think you can use a hardware-camera beside the OpenCV-camera.
CameraBridgeViewBase cameraBridgeViewBase;
List list;
arrayListForWidth = new ArrayList<>();
arrayListForHeight = new ArrayList<>();

Android getSupportedVideoSizes always returns null
https://stackoverflow.com/a/5934967/10751265
Use both getSupportedVideoSizes and getSupportedPreviewSizes
if (Camera.getParameters().getSupportedVideoSizes() != null || cam_index.getParameters().getSupportedPreviewSizes() != null) {
    if (cam_index.getParameters().getSupportedVideoSizes() != null)
        list = cam_index.getParameters().getSupportedVideoSizes();
    else
        list = cam_index.getParameters().getSupportedPreviewSizes();

    for (Object e_list : list) {
        arrayListForWidth.add(((Camera.Size) e_list).width);
        arrayListForHeight.add(((Camera.Size) e_list).height);
    }
}

After getting arraylists for width and height, you can use them for OpenCV-camera
cameraBridgeViewBase.setMaxFrameSize(arrayListForWidth.get(i), arrayListForHeight.get(i));


Flurl exception not being caught

Question: I don't understand why but I'm receiving Flurl Exceptions and those are not being caught by the try/catch block. Any ideas on why that's happening?
Here's the code:
<code>try
{
    var x = await Utils.Sales.GetUrl()
        .PostJsonAsync(new Sale
        {
            MerchantId = Constants.Sandbox.MerchantId
        })
        .ReceiveJson<Sale>();
    var b = x;
}
catch (FlurlHttpTimeoutException)
{
    //LogError("Timed out!"); //todo:
}
catch (FlurlHttpException ex)
{
    var x = ex.Message;
    //todo:
    //if (ex.Call.Response != null)
    //    LogError("Failed with response code " + call.Response.StatusCode);
    //else
    //    LogError("Totally failed before getting a response! " + ex.Message);
}
catch (Exception ex)
{
    var a = ex.Message;
}
</code>
Here's the output (the only reason why I know the exception is being thrown):
Comment: Maybe it is being caught in the library or the method you're calling?
Comment: @MehrzadChehraz I'm sorry but I couldn't understand... Are you suggesting that I have another try/catch somewhere or that the exception is being handled by some other library?
Comment: @eestein It's possible that the library is throwing the exception, catching it, and handling it. The output logs is showing thrown exceptions (including those which have been caught)
Comment: @Rob I understand. But the library itself provides the Exception treatment option and on the creator's page he uses that same code as an example. With that in mind I think that wouldn't be the case.
Comment: Anyone besides you working on this project? All I can think of is that someone may have [configured a global error handler](http://tmenier.github.io/Flurl/configuration/) that calls `call.ExceptionHandled = true`, which would prevent the exception from bubbling up to your code.
Comment: @ToddMenier hi Todd, only myself. The only thing I configure globally is the ModernHttpClient. I don't know why that's happening (the exception being handled) but I found out why the exception was thrown after moving my code to use restclient. It was the TLS version. The API used 1.2 but my project is running on .NET 4.5.2 and only 4.6+ has OOTB support. Is there a way to force that on flurl? I'd like to use it (I'm using it on 2 other projects) but I can't upgrade the 4.5.2 project right now. If you can try to take a look at that exception being caught. Lemme know if you need more code/info!
Answer: Maybe this page will help https://msdn.microsoft.com/zh-cn/library/jj619227.aspx
Sorry don't have a english version, you can try google translate it.
It's someting wrong with you catch exception type or await code.
Try this way catch your exception:
```
<code>try
{
    await t1;
}
catch (AggregateException ex)
{
    var innerEx = ex.InnerExceptions[0];
    if (innerEx is NotSupportedException)
    {
        ...
    }
    else if (innerEx is NotImplementedException)
    {
        ...
    }
    else
    {
        ...
    }
}
</code>
```
Comment: I don't understand what's written there but I understand the code. I think it's the same thing I'm doing, ain't it?
Comment: same code like yours it's the wrong catch example, below is the right way catch exception, and show some other way handle exception of await in this article. Also some explain of thoese design. I only do a quick read get some summary.

Flurl exception not being caught