signaling a sleeping thread

Question: I'm new to multithreading in c# and am confused among all thread stuff.
here is what I'm trying to have:
public class TheClass
{
    Thread _thread;
    bool _isQuitting;
    bool _isFinished;
    object jobData;
    public void Start()
    {
        jobData = new object();
        _thread = new Thread(new ThreadStart(Run));
        _thread.Start();
    }
    private void Run()
    {
        while (!_isQuitting)
        {
            lock (jobData) // or should i use mutex or monitor?
            {
                DoStuff();
            }
            // sleep till get triggered
        }
        DoCleanupStuff();
        _isFinished = true;
    }

    public void AddJob(object param)
    {
        jobData = param;
        //wake up the thread
    }
    public void Stop()
    {
        _isQuitting = true;
        //wake up & kill the thread
        //wait until _isFinished is true
        //dispose the _thread object
    }
}

in this class, what is the most efficient method to achieve commented out phrases and for overall performance?
Comment: Just a few comments: ① Your `jobData` object is initially null, so if the user calls `Run` before calling `AddJob`, it crashes. To fix this, you can change `object jobdata;` to `object jobdata = new object();`. ② The `Run` method does not seem to use its parameter at all, so you can just remove it and use `ThreadStart` instead of `ParameterizedThreadStart`.
Answer: Consider using Monitor.Wait() and Monitor.Pulse().
For example:
object locker = new object();

private void Run()
{
    while (!_isQuitting)
    {
        lock (locker)
        {
            Monitor.Wait(locker);
            DoStuff(jobData);
        }
    }
    DoCleanupStuff();
}

public void AddJob(object param)
{
    // Obtain the lock first so that you don't
    // change jobData while the thread is processing it
    lock (locker)
    {
        jobData = param;
        Monitor.Pulse(locker);
    }
}

public void Stop()
{
    lock (locker)
    {
        _isQuitting = true;
        Monitor.Pulse(locker);
    }

    // Wait for the thread to finish — no need for _isFinished
    _thread.Join();
}

However, notice that in my code you still have only one jobData object — the consequence being that AddJob() will wait for the current job to finish processing. This may not be what you want. Perhaps you should have a Queue<T> of job data objects; AddJob would Enqueue an item and Run would keep Dequeue'ing until the queue is empty. If you do this, the lock statement in Run should encompass only the access to the queue, not the entire processing stage.
Answer: I don't know about the performance, but it looks like you want AutoResetEvent.
This certainly gives you one of the simplest ways to do what you're describing.  Test it out, and if you find performance is an issue, then worry about another way to do it.
Answer: It looks to me like you want to use the producer/consumer pattern. This is most easily accomplished using a blocking queue. Once you have that then everything else is easy. You can find an implementation here or you can use the BlockingCollection class available in 4.0.
Note: Hardening code is omitted for brevity.
public class TheClass
{
    private Thread m_Thread;
    private BlockingCollection<object> m_Queue = new BlockingCollection<object>();
    private CancellationTokenSource m_Cancellation = new CancellationTokenSource();

    public void Start()
    {
        m_Thread = new Thread(new ThreadStart(Run));
        m_Thread.IsBackground = true;
        m_Thread.Start();
    }

    private void Run()
    {
        while (true)
        {
            try
            {
                object job = m_Queue.Take(m_Cancellation.Token);
            }
            catch (OperationCanceledException)
            {
                break;
            }
        }
    }

    public void AddJob(object param)
    {
        m_Queue.Add(param);
    }

    public void Stop()
    {
        m_Cancellation.Cancel();
        m_Thread.Join();
    }
}

signaling a sleeping thread


I am trying to upgrade and Composer is complaining. How do I figure out what the actual issue is and fix it?

Question: I am trying to update my Drupal 9 site to Drupal 10. I installed the Upgrade status module (and removed it before trying to update); my site is good with the exception of updating the Dynamic Entity Reference module, which requires Drupal 10.
I followed the Upgrading a Composer-based site documentation but when I try to run composer update, I get these errors.
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - symfony-cmf/routing[1.4.0, ..., 1.4.1] require php ^5.3.9|^7.0 -> your php version (8.2.9) does not satisfy that requirement.
    - drupal/core[8.9.11, ..., 8.9.20] require php ^7.0.8 -> your php version (8.2.9) does not satisfy that requirement.
    - Root composer.json requires drupal/linkchecker ^1.1 -> satisfiable by drupal/linkchecker[1.1.0].
    - drupal/core-recommended 10.0.2 requires drupal/core 10.0.2 -> satisfiable by drupal/core[10.0.2].
    - Conclusion: don't install drupal/core 10.0.2 (conflict analysis result)
    - drupal/core-recommended 10.0.3 requires drupal/core 10.0.3 -> satisfiable by drupal/core[10.0.3].
    - Conclusion: don't install drupal/core 10.0.3 (conflict analysis result)
    - drupal/core-recommended 10.0.4 requires drupal/core 10.0.4 -> satisfiable by drupal/core[10.0.4].
    - Conclusion: don't install drupal/core 10.0.4 (conflict analysis result)
    - drupal/core-recommended 10.0.5 requires drupal/core 10.0.5 -> satisfiable by drupal/core[10.0.5].
    - Conclusion: don't install drupal/core 10.0.5 (conflict analysis result)
    - drupal/core-recommended 10.0.6 requires drupal/core 10.0.6 -> satisfiable by drupal/core[10.0.6].
    - Conclusion: don't install drupal/core 10.0.6 (conflict analysis result)
    - drupal/core-recommended 10.0.7 requires drupal/core 10.0.7 -> satisfiable by drupal/core[10.0.7].
    - Conclusion: don't install drupal/core 10.0.7 (conflict analysis result)
    - drupal/core-recommended 10.0.8 requires drupal/core 10.0.8 -> satisfiable by drupal/core[10.0.8].
    - Conclusion: don't install drupal/core 10.0.8 (conflict analysis result)
    - drupal/core-recommended 10.0.9 requires drupal/core 10.0.9 -> satisfiable by drupal/core[10.0.9].
    - Conclusion: don't install drupal/core 10.0.9 (conflict analysis result)
    - drupal/core-recommended 10.0.10 requires drupal/core 10.0.10 -> satisfiable by drupal/core[10.0.10].
    - Conclusion: don't install drupal/core 10.0.10 (conflict analysis result)
    - drupal/core-recommended 10.0.11 requires drupal/core 10.0.11 -> satisfiable by drupal/core[10.0.11].
    - Conclusion: don't install drupal/core 10.0.11 (conflict analysis result)
    - drupal/core-recommended 10.1.0 requires drupal/core 10.1.0 -> satisfiable by drupal/core[10.1.0].
    - Conclusion: don't install drupal/core 10.1.0 (conflict analysis result)
    - drupal/core-recommended 10.1.1 requires drupal/core 10.1.1 -> satisfiable by drupal/core[10.1.1].
    - Conclusion: don't install drupal/core 10.1.1 (conflict analysis result)
    - drupal/core-recommended 10.1.2 requires drupal/core 10.1.2 -> satisfiable by drupal/core[10.1.2].
    - Conclusion: don't install drupal/core 10.1.2 (conflict analysis result)
    - drupal/core-recommended 10.1.3 requires drupal/core 10.1.3 -> satisfiable by drupal/core[10.1.3].
    - Conclusion: don't install drupal/core 10.1.3 (conflict analysis result)
    - drupal/core-recommended 10.1.4 requires drupal/core 10.1.4 -> satisfiable by drupal/core[10.1.4].
    - Conclusion: don't install drupal/core 10.1.4 (conflict analysis result)
    - drupal/core-recommended 10.1.5 requires drupal/core 10.1.5 -> satisfiable by drupal/core[10.1.5].
    - Conclusion: don't install drupal/core 10.1.5 (conflict analysis result)
    - drupal/core-recommended 10.1.6 requires drupal/core 10.1.6 -> satisfiable by drupal/core[10.1.6].
    - Conclusion: don't install drupal/core 10.1.6 (conflict analysis result)
    - drupal/core[8.9.0, ..., 8.9.10] require symfony-cmf/routing ^1.4 -> satisfiable by symfony-cmf/routing[1.4.0, 1.4.1].
    - drupal/core-recommended 10.0.1 requires drupal/core 10.0.1 -> satisfiable by drupal/core[10.0.1].
    - Conclusion: don't install drupal/core 10.0.1 (conflict analysis result)
    - drupal/linkchecker 1.1.0 requires drupal/core ^8.9 || ^9.2 -> satisfiable by drupal/core[8.9.0, ..., 8.9.20, 9.2.0, ..., 9.5.11].
    - You can only install one version of a package, so only one of these can be installed: drupal/core[8.0.0, ..., 8.9.20, 9.0.0, ..., 9.5.11, 10.0.0, ..., 10.1.6].
    - You can only install one version of a package, so only one of these can be installed: drupal/core[8.7.0, ..., 8.9.20, 9.0.0, ..., 9.5.11, 10.0.0, ..., 10.1.6].
    - drupal/core-recommended 10.0.0 requires drupal/core 10.0.0 -> satisfiable by drupal/core[10.0.0].
    - Root composer.json requires drupal/core-recommended ^10 -> satisfiable by drupal/core-recommended[10.0.0, ..., 10.1.6].

I tried specifically updating symfony-cmf/routing to the 2.x version, but that still threw errors.
I really struggle digging through the lines of problems to figure out what the actual issue is.
Does anybody know how I can fix this and explain how you figured that out, so that I can hopefully know for the future?
Comment: drupal/linkchecker 1.1.0 requires drupal/core ^8.9 || ^9.2
Comment: Sometimes when you have a single module to update (Dynamic Entity Reference), composer can get stuck.  Assuming you are using version control for your site, delete `composer.lock` and the `vendor` directories, and then run `composer clear-cache`.  This will wipe out all your locally installed package info.  Then try running `composer update` to generate a fresh `composer.lock`.
Comment: To figure out why, you can run `composer prohibits drupal/core 10.1.6`
Comment: Is the version of PHP outdated as well?
Comment: @cilefen, the question is why it didn't show in the upgrade status module. Eluchel, can you reinstall the upgrade status module and check if everything is green?
Comment: Does upgrade status scan disabled modules?
Comment: Yes, and it tells you to remove it because you don't use it anyway.
Comment: @Kevin no php was just updated to 8.2+
Answer:
I am trying to update my Drupal 9 site to Drupal 10. I installed the
Upgrade Status module (and removed it before trying to update)

This is great, this should prevent any composer errors. Reinstall the Upgrade Status module to look again. Is there an entry for the Link Checker module? It should be in the Update section, or if not installed by Drupal in the Remove section with the description:

The likely best action is to remove projects that are uninstalled. Why
invest in updating them to be compatible if you are not using them?


Is the boundary of a clopen set the empty set?

Question: If a set $X$ is closed then $\overline{X} = X$ and if it is open then $X^o = X$, so does this mean that for a subspace $X$ of a topological space which is both open and closed (for example in a partition) the boundary given by $\overline{X} \backslash X^o$ is just the empty set?
Conversely does this mean that all sets, in which the boundary is the empty set, are clopen sets?
Comment: Yup! Your reasoning is correct. You can write up your solution as an answer (and accept it, if you'd like). This is explicitly encouraged by the SE network of sites; see [here](http://meta.stackexchange.com/questions/12513/should-i-not-answer-my-own-questions) and [here](http://blog.stackoverflow.com/2011/07/its-ok-to-ask-and-answer-your-own-questions/).
Answer: This CW answer intends to remove this question from the Unanswered queue.

The reasoning is correct, as Zev Chonoles points out.


Bounding the trace-class norm of integral operator on $L^2(\mathbb{R})$

Question: Consider an integral operator on $L^2(\mathbb{R})$ with kernel $K : \mathbb{R}^2 \to \mathbb{C}$. My question is if it is possible to bound the trace-class norm of $T$ based on properties of $K$?
This problem appears to be have been studied in the case of $L^2(0,1)$ but I haven't been able to find anything in the non-compact case apart from a remark in "Kernels of trace-class operators" by Chris Brislaw saying that if the kernel function is in the Schwarz class, the operator is trace-class.
Answer: I will assume that the operator you speak of is trace-class. Now, it turns out that there is no way to bound the trace norm for some trace class operator $A$, i.e. $\|A\|_{1}$ in the same sense that we can not bound the $L_{1}(\mathbb{R})$ norm for $L_{p}(\mathbb{R})$ spaces. Schatten norms $\|A\|_{p}:= \big(Tr|A|^{p}\big)^{\frac{1}{p}}$ follow the same inclusion pattern as $L_{p}(\mathbb{R})$ spaces do. i.e
$$
L_{p}(\mathbb{R}) \subset L_{q}(\mathbb{R})
$$
when $p>q$. It also turns out that Hoelder's inequality holds for these norms. Consequently
$$ \|A\|_{\infty}\leq... \leq \|A\|_{2}\leq\|A\|_{1}$$
where $\|A\|_{\infty}$ is just the operator norm. It turns out that all of the even cases are easy to compute while the odd cases are pretty much impossible without knowing the spectral decomposition of your integral's kernel. Why? Because you must compute the absolute value of an integral operator.
Now, if your integral operator $T$ is positive then $\|T\|_{1} = Tr\{T\}$ and the trace is easily computed. Also, if you can argue that your operator is a product of two Hilbert Schmidt operators (Schatten class $\|...\|_{2}$) and you know what they are then using Hoelder's should do the trick because then you would only have to take a Hilbert Schmidt norm $\|...\|_{2}$ and that is easy.


catboost does not overfit - how is that possible?

Question: I'm fitting and evaluating a CatBoostRegressor and a XGBRegressor to the same regression problem. I tried matching their hyperparameters as closely as possible, yet I'm seeing something strange: catboost test error is monotonically decreasing! Why is that? NOTE that I switched off the fancy boosting_type and it's plain.
catboost learning curve:

xgboost learning curve:

catboost get_all_params:
{'nan_mode': 'Min',
 'eval_metric': 'RMSE',
 'iterations': 1000,
 'sampling_frequency': 'PerTree',
 'fold_permutation_block': 0,
 'leaf_estimation_method': 'Newton',
 'boosting_type': 'Plain',
 'feature_border_type': 'GreedyLogSum',
 'bayesian_matrix_reg': 0.1000000015,
 'l2_leaf_reg': 3,
 'random_strength': 1,
 'rsm': 1,
 'boost_from_average': True,
 'model_size_reg': 0.5,
 'approx_on_full_history': False,
 'subsample': 0.8000000119,
 'use_best_model': True,
 'random_seed': 0,
 'depth': 6,
 'has_time': False,
 'fold_len_multiplier': 2,
 'border_count': 254,
 'classes_count': 0,
 'sparse_features_conflict_fraction': 0,
 'leaf_estimation_backtracking': 'AnyImprovement',
 'best_model_min_trees': 1,
 'model_shrink_rate': 0,
 'loss_function': 'RMSE',
 'learning_rate': 0.009999999776,
 'score_function': 'Cosine',
 'task_type': 'CPU',
 'leaf_estimation_iterations': 1,
 'bootstrap_type': 'MVS',
 'permutation_count': 4}

xgboost get_params:
{'base_score': 0.5,
 'booster': 'gbtree',
 'colsample_bylevel': 1,
 'colsample_bynode': 1,
 'colsample_bytree': 1,
 'gamma': 0,
 'importance_type': 'gain',
 'learning_rate': 0.01,
 'max_delta_step': 0,
 'max_depth': 6,
 'min_child_weight': 1,
 'missing': None,
 'n_estimators': 1000,
 'n_jobs': 1,
 'nthread': None,
 'objective': 'reg:linear',
 'random_state': 0,
 'reg_alpha': 0,
 'reg_lambda': 1,
 'scale_pos_weight': 1,
 'seed': None,
 'silent': False,
 'subsample': 1,
 'verbosity': 1}

Comment: In addition to the general principles outlined in the answer from @usεr11852 it seems that `catboost` is still learning (very slowly) at 700 trees. The minimum test MSE is about 1.2 for `xgboost` while the last test MSE for `catbost` seems to be about 1.4; see if going out to a few thousand trees finds a minimum closer to 1.2 for `catboost`.
Comment: @EdM (+1) Yeah, obviously, I wanted to make that point too but forgot! `xgboost`  achieves a substantially better minima way sooner.
Answer: As it stands the two runs are not directly comparable. For example, off the bat, we can see that:

catboost uses a stronger $L_2$ regularisation on the weights ($3$ instead of $1$ in xgboost).
catboost uses different bagging/subsampling in terms of rows ($0.8$ instead of $1.0$ in xgboost).
catboost uses a different way than xgboost to built its trees; symmetric instead of best-first in XGBoost.
catboost uses an extra regularisation parameter (bayesian_matrix_reg) to regularise leaf values calculation (the non-diagonal ones when computing the hessian on the leafs); strictly speaking xgboost do not have the same functionality.

Please note that the above points are not even a very in-depth look. While we might expect the same qualitative behaviour between different implementations of a general computational framework (e.g. lowering the depth of the base-learner trees decreases the chance of over-fitting), the effect size might not be comparable. As these implementations incorporate a number of computational techniques to accelerate and/or make them more stable, the direct comparison of their behaviour is unreliable.


Python dictionary switching keys around in dictionary

Question: So I have a dictionary in python in which I have a number for the key with a value attatched to it.
myDictionary = {"0" :0, "1":0, "2":0, "3":0, "4":0, "5":0, "6":12, "7":0,"8":0,"9":0,"10":0,"11":0, "12":0,"13":12}

I run a doctest that says:
>>> myDictionary = {"0" :0, "1":0, "2":0, "3":0, "4":0, "5":0, "6":12, "7":0,"8":0,"9":0,"10":0,"11":0, "12":0,"13":12}
>>> new_Val = 0
>>> method0 = WordClass (new_Val, myDictionary)
True

I was doing some debugging ad printed out my dictionary to make sure I was going through the right values in the dictionary. When I printed it out, it looked like this:
{'11': 4, '10': 4, '13': 0, '12': 4, '1': 4, '0': 4, '3': 4, '2': 4, '5': 4, '4': 4, '7': 4, '6': 0, '9': 4, '8': 4}

They are all out of order. Does python do that by default when storing memory or something? If so, is there some documentation somewhere that I can look at?
Thank you
Comment: [Dictionaries](https://docs.python.org/2/tutorial/datastructures.html#dictionaries) are unordered by definition. Why not use a list?
Answer: Dictionaries in python are unordered.  Do you actually need an order?  If you elaborate on this a bit people may be able to help you more.  You can try using something like https://docs.python.org/2/library/collections.html#collections.OrderedDict if you really need it to be ordered.
Comment: Why do they need to be ordered?  You could do `for key in dict` or `for item in dict.items()` with no expectation of getting them back in any particular order, or even the same order twice.
Comment: Well, they have to be ordered to iterate through them right? I want to be able to get the value at each one going through a for loop
Comment: @LearnLanguages96, you can't iterate through a ```dict``` directly.  What you can do is generate a list of keys, and then loop through that and sequentially call up the values.  This is what implicitly happens when you do ```for thing in a_dict:```, each ```thing``` will be a key of the dictionary ```a_dict``` (which pops up in an arbitrary order)
Answer: Python dictionary keys are unordered.  If you want them back in a particular order, you need to sort them.  If you want a dictionary to remember the order in which keys were added, use OrderedDict() from collections.
More info: https://docs.python.org/3.3/library/collections.html#collections.OrderedDict


SQL: Is it possible to insert into two tables at the same time with autogenerated id output from first table into second

Question: My database contains two tables FileStore and FileRepository.
The FileStore table contains 3 columns Id (autogenerated uniqueidentifier), FileName and Description
-> In Initial state with demo data

The FileRepository table contains 3 columns Id (autogenerated uniqueidentifier), Name and FileId (this refers to the Id column in FileStore table) -> In Initial state with demo data

I get an array of FileStore Ids as a search criteria. With the same I need to create a duplicate row in the FileStore table first for each of the criteria satisfied. I need to do the duplicate row creation for the second table FileRepository as well based on the same data on the FileId column. Here but I need to update the newly created row's FileId column with the autogenerated Id column from the FileStore operation.
Say referring to the attached images if I need to duplicate Files File 1(with Id b3304dc4-4f2e-46d4-8f64-a597edb02e96) and File 2(with Id 7cb40baf-1ecf-4e5f-92ff-57029a20e623) this is how the tables should have data after the operation
FileStore db after duplication should have data thus:

FileRepository db after duplication should have data thus:

Which is the best way to do this? Is it possible to achieve this with a query without any loops?
For the first table I can insert and get the inserted Ids thus:
INSERT INTO FileStore(FileName,Description)
OUTPUT INSERTED.Id as InsertedIds
SELECT
FileName, Description
from FileStore
where Id IN ('b3304dc4-4f2e-46d4-8f64-a597edb02e96','7cb40baf-1ecf-4e5f-92ff-57029a20e623')

But was unsure about the query to update the FileRepository table which takes the InsertedIds as input
INSERT INTO FileRepository(Name,FileId)
SELECT
Name, {{How do I use InsertedDetails here?}}
from FileRepository
where FileId IN ('b3304dc4-4f2e-46d4-8f64-a597edb02e96','7cb40baf-1ecf-4e5f-92ff-57029a20e623')

PS: This is just a reference table I created for this question. Please let me know in case I need to make it more clear
Comment: A DML statement can only affect one object at a time. If you need to effect multiple objects, you need multiple statements. Seems like you just need to be using the `OUTPUT` clause here, to get the inserted data, and then `INSERT` that into another table? To answer your question *"Is it possible to achieve this with a query without any loops"* There are ***very*** few times you ever need a loop in SQL. SQL isn't a programming language, it's a query language; it excels at set-based solutions are performs poorly at iterative ones. If you're thinking of looping, you're probably doing it wrong.
Comment: Well even I was of the same assumption of using the OUTPUT clause but lil unsure of using it when we have multiple return values
Comment: `OUTPUT` returns a dataset, so I'm not sure what your mean by when you have multiple values. `OUTPUT` can only ever return 1 dataset, not many.
Comment: Well probably I was not clear with the doubt I had. I agree the OUTPUT clause returns a dataset. Well I needed to input the returned Ids into the second table mapping based on which file duplicated returns the corresponding Id. The mapping table actually needs to be updated accordingly
Comment: @Larnu Have updated my question to make it more clear
Answer: As I mention, you need to use the OUTPUT clause. This is pseudo-SQL in the abscence of consumable sample data and expected results. You'll need to remove/change the parts in braces ({}) appropriately:
DECLARE @Output table (ID uniqueindentifier,
                       {Other Columns});

INSERT INTO FileStore(FileName,Description)
OUTPUT INSERTED.Id, {Other Columns}
INTO @Output
SELECT FileName,
       Description
from FileStore
where Id IN ('b3304dc4-4f2e-46d4-8f64-a597edb02e96','7cb40baf-1ecf-4e5f-92ff-57029a20e623');

INSERT INTO FileRepository(Name,FileId)
SELECT FR.Name,
       O.ID
from FileRepository FR
     {CROSS} JOIN @Output O {ON Some Condition}
where FileId IN ('b3304dc4-4f2e-46d4-8f64-a597edb02e96','7cb40baf-1ecf-4e5f-92ff-57029a20e623')

Comment: If you feel this answer is unhelpful, I would greatly appreciate you explaining why so that I can look to improve it. Thank you.
Answer:
At first, insert your parent table's data.
Then
INSERT INTO FileRepository (`id`, `Name`,`FileId`)
VALUES('id_or_auto_generated','name value', SELECT SCOPE_IDENTITY())

SELECT SCOPE_IDENTITY(); will return the most recently auto-generated id of the SQL server database connection.
For other databases : Follow this post
Comment: LAST_INSERT_ID()/ SCOPE_IDENTITY() returns the first generated integer. So this will not work in my case
Comment: Yes I am. But the autogenerated Id column is UNIQUEIDENTIFIER


Geometric Multiplicity, Eigenspace of Matrix

Question: If $A$ is an $r$ x $s$ matrix and B is an $s$ x $r$ matrix.
$E_\mu(C)$ is the eigenspace of square matrix C with eigenvalue $\mu ≠ 0$.
Proof:

$dimE_\mu(AB) = dimE_\mu(BA)$

I imagine one would need to find the basis of eigenvectors for both spaces, but I'm not sure how...
Answer: Hint: If $v$ is an eigenvector for $AB$, then $Bv$ is an  ...
Comment: Eigenvector of $BA$. Does that imply that the spaces have the same number of eigenvectors?
Comment: I still don't understand... sigh
Comment: You have an invertible linear map taking the eigenspace for one onto the eigenspace for the other.  Such maps take a basis to a basis, and thus preserve dimension.
Answer: Here's another way to look at it. Let $\mu \neq 0$. By the standard argument (mentioned in Robert Israel's answer), we have well-defined linear maps $T : E_\mu(AB) \to E_\mu(BA)$, $x \mapsto Bx$ and $S : E_\mu(BA) \to E_\mu(AB)$, $y \mapsto Ay$. Note that $T$ and $S$ are almost each other's inverse:
\begin{align*}
STx &= ABx = \mu x;\\[1ex]
TSy &= BAy = \mu y.
\end{align*}
Therefore $T$ (resp. $S$) is an isomorphism with inverse $T^{-1} = \frac{1}{\mu} S$ (resp. $S^{-1} = \frac{1}{\mu} T$). Since $E_\mu(AB)$ and $E_\mu(BA)$ are isomorphic, they have the same dimension.


Gerar Log por data do dia C#

Question: Tenho esse código abaixo, teria como gerar Log pela data do dia? Exemplo: log_29072020.txt
private void Log(string mensagem)
{
    string ficheiro = Environment
        .GetFolderPath(Environment.SpecialFolder.MyComputer)
            + @"\Debug\Log.txt";

    if (!Directory.Exists(Path.GetDirectoryName(ficheiro)))
        Directory.CreateDirectory(Path.GetDirectoryName(ficheiro));

    StreamWriter file = new StreamWriter(ficheiro, true, Encoding.Default);
    file.WriteLine(DateTime.Now + " > " + mensagem);
    file.Dispose();
}

E criar uma ação do que foi feito do sistema, apenas tenho a mensagem.
Answer: Podes formatar o output com Datetime.Now.ToString("dd mm yy") ou algo do género. Caso queiras dar uma vista de olhos na documentação de algum loger como o log4net, aqui podes encontrar exemplos de como fazer o que pretendes usando essa ferramenta. Além de que evitas ter de implementar o acesso a ficheiros e podes ainda imprimir os logs para vários outputs.
Answer: Basicamente no nome do arquivo coloque da seguinte forma:
@"\Debug\log" + DateTime.Now.ToString("ddMMyyyy") + ".txt"

que a formatação especificada na sua pergunta. Exemplo final:
private void Log(string mensagem)
{
    string ficheiro = Environment
        .GetFolderPath(Environment.SpecialFolder.MyComputer)
            + @"\Debug\log_" + DateTime.Now.ToString("ddMMyyyy") + ".txt";

    if (!Directory.Exists(Path.GetDirectoryName(ficheiro)))
        Directory.CreateDirectory(Path.GetDirectoryName(ficheiro));

    StreamWriter file = new StreamWriter(ficheiro, true, Encoding.Default);
    file.WriteLine(DateTime.Now + " > " + mensagem);
    file.Dispose();
}

Estou me atentando ao nome do arquivo, não se o código é a melhor forma de resolver o problema.
Comment: Obrigado Virgilio Novic
Comment: se for a resposta esperada por favor assinale como resposta @EvanilsonSilva
Comment: nesse mesmo código teria como restringir a quantidade de log criado, exemplo: quando chegasse em uma quantidade de 30 logs, no log seguinte ele apagasse ou sobrescrevesse o primeiro log, assim ficando sempre a quantidade de 30 logs, teria como fazer ?
Comment: @EvanilsonSilva sim, programação é ilimitada, só que ai já é outra duvida, cada duvida gera uma pergunta aqui no pt.stackoverflow para melhor organização ... então crie outra pergunta
Comment: Entendo, obrigado mais uma vez @Virgilio Novic

Gerar Log por data do dia C#


How to interpret infinite part correlations (caused by Moore-Penrose generalised inverse)?

Question: I'm using R's ppcor package and from there spcor function to calculate the pairwise semi-partial (part) correlations. In my data there are 11 variables and 95 observations.
When calculating partial correlations I get a warning that "The inverse of variance-covariance matrix is calculated using Moore-Penrose generalized matrix inverse due to its determinant of zero" and some of the returned estimates are -Inf.
How should (or could) I interpret these values?
Comment: Btw, Gavin edited the title and the question. In the future, it might not be the best idea to fix typos from quoted error messages as those are something that people copy and paste to google when experiencing the same problem
Answer: If you have zero determinant on your covariance matrix, then I guess your data is unconditionally independent of at least one variable, or a linear combination thereof. The semi-partial correlations over that variable will naturally be zero. So you can probably get away with setting the returned estimates to zero. If you want a more principled approach, do a singular-value decomposition on the covariance matrix to identify that variable and eliminate it from your dataset.


Learning an instrument online

Question: I took ballet and with ballet you gain something called muscle memory and if you learn incorrectly, it's almost impossible to become a great dancer. Because of this, you can't learn ballet out of a book or from a video -- you need an instructor to say "You're doing a great job" or "You need to do this instead."
Is learning an instrument online a bad idea because of the above reason or any other reason?
I would like to learn the flute, but I live pretty much in the middle of nowhere. I see that there are plenty of learn flute online courses, but I'm wondering if anyone has had any success with learning an instrument over the Internet, out of a book, from videos, etc? I'm not talking about people who see an instructor and then go home and practice out of a book, but rather those who never have the help of an instructor.
Edit: By "online", I mean courses in which I'm not interacting with an instructor.
Answer: I think if one wanted to be a concert pianist or part of a symphony or something, there's no question that one should get a good teacher.  Precision is necessary in these areas, and precision is exceptionally difficult to teach oneself.  As well, you might never be exposed to some concepts through picking up things on your own that a teacher would deem absolutely necessary.
That said, it's not necessary to have a teacher in order to be a decent musician.  While you might never go to a performance of amateur ballet dancers, people go see amateur(ish) musicians in concert all the time.  Technique is rarely the focus, but rather creativity and artistry.  These things can be enhanced by formal training but aren't really taught.
It's certainly easy to develop bad habits, but I think they can be corrected more easily in music than in ballet.  My third piano teacher was much more competent than my first two, and managed to smack most of my bad habits out of me.  It's also easy to ignore certain areas, such as theory and sight reading; but many people manage to ignore them even with a teacher.  Memorizing a song can hide that you can't sightread quickly, and that sort of thing.
If you're focused enough, you can definitely achieve a high skill level without a teacher.
Comment: Also, a good student will respond well to any teacher giving criticism. If he goes to a master class and the teacher comments on his posture, he will work on his own to correct it. (Of course this is true with the traditional teacher/student relationship as well, but it doubly important when studying independently.)
Answer: Is the quality of online lesson good?
With very detailed, in-depth instructions like Youtube:ProfessorV's Violin lessons, one can confidently start learning an instrument. (find something similar for your instrument)
Are you aware of your mistakes?
Would you know if your posture is wrong or stressing some of your muscles unnecessarily? Could you detect your intonation flaws? If you've already learnt an instrument, and/or quite aware of technique, you will probably avoid getting stuck with bad habits.
As you say you've learnt ballet, you probably know the proper learning process, rather than hacking and learning to play a few cool tunes. There are very useful learning resources online. I don't see why you should hesitate, especially when there's no teacher around.
tip: record yourself
Comment: +1 for "record yourself." Both audio and video recording can help you identify problems.
Answer: From learning the flute as a kid, I would say that you will probably benefit from an instructor. But I don't think you need to see the instructor very often. If you can get to an instructor once every couple of months to make sure you aren't making any mistakes in your basic technique, that is probably enough.
So maybe instead of an instructor, you can call it a "coach". :-)
Answer: I took 4-5 years of lessons starting at age 8 before dropping them, and here is my information.
You don't have to have a teacher every week for a year or more like some people do. You might do well to get started on your own and then have a teacher for about a month to check that you are on course. It is up to you and in this point of view you will probably know best.
The most likely bad habits I know of (that a teacher would probably point out early on) are.

Unnecessary stress / bad posture or hand position. Stay relaxed, don't use the ends of your joints. If you are falling from a second story, you want to land on your feet and not have straight knees, You want to make sure you are using your muscle and not the joint endings.
Allowing an out of tune piano to seem normal to your ear. You can tune your own piano, but you probably don't want to learn that until you can play it. You can ask someone else to see if it is in tune or you can practice on different pianos.

Also, keep in mind that learning to play by ear and by sight are two different things.  Any one of these can be dropped entirely for you to play piano, but you may not want to. Memorizing is also a part of sight reading that can be dropped. Teachers I know push for even learning across all of these. Students I know (probably because of the books they use), easily drop the part of learning by ear and the teacher does not get much practice on the ear part of have a fun time handling a person who is the other way around.
Whatever you do, I would advise learning sheet music enough so you can learn a song (even if it is slow work). If you have a good ear, you may find you want to take a melody or a song you have heard and work it out on the piano, in which case you may look at adding accompaniment to a tune in a separate question.
Comment: -1 Learning to read music solidly is a must. You are correct that too many students drop the ear part entirely, but it's too easy to go in the other direction too (read, Susuki) where the student is extremely advanced but can play sheet music only on the most basic level.
Comment: +1 Depends on your instrument/style - many of the most successful musicians in the world don't read sheet music, or learned after they became famous. I happened to learn violin when very young, so I can read music, but in my current performances I almost never use music so it can be irrelevant.
Comment: @Michael: I tend to agree with @Dr Meyhem, but I know this is subjective. Here are some examples for those who are interested. http://music.stackexchange.com/questions/63/are-there-any-successful-renowned-composers-who-dont-know-sheet-music-notation/.
Answer: During my time, there was no such thing as the internet. However, there were cassette tapes, books and watching friends and performers playing. Sometimes, I can consult them; sometimes I just watch and ask no questions.
That is the closest experience I have that would compare with the internet.
However, for me, the desire is very intense.
Eventually, I became a Play By Ear Coach and by today, after 25 years, I and my team have coached about 5000 students. With all the experiences combined, I have compiled our training into Video Ebooks detailing exactly what to do like how we teach on a personal basis. In fact, I think they are better because all the correct terms and methods are clearly expressed across. It is possible that sometimes, due to human elements, a human coach can miss out on important details. With Video Ebooks, you can't miss out unless you are careless.
As the others have mentioned, you DON'T need a coach ALL THE TIME - only at times when you want someone to assess what you have done and to give pointers where to move next. For that SKYPE is a very useful invention. And the technology has improved so much that the Video Conferencing part has become very advanced such that a coach and watch exactly what you are doing and then give corrections.
If the circumstances warrant it and you have no other choice; or because of money constraints, give ONLINE LEARNING A GO. If you do well, you save money. If it is not for you, you can always start looking for coach.
Personally, I think if your desire to get the music right is very strong, you don't have to worry about "Muscle Memory".
Answer: Internet video lessons are an amazing resource - whether free or paid - and good ones will show you great technique plus you can watch over and over rather than get confused and have to wait until your next lesson to check with the tutor.
The main thing you miss is someone watching you and noticing the things you are doing wrong.
But "online" doesn't have to mean online videos only. Lots of people do traditional lessons online over tools like Skype, in fact I think many sites with video lessons offer this kind of personal tuition as well.
Answer: I guess there are instruments, where the online approach is more difficult. For sure the double reed instruments fall into this category, where every so often my teacher says: 'Let my try that reed', and after short diagnosis resorts to the tools.
In the initial phase I would strongly advise against it - I tried learning bassoon on myself (i.e. even without online teacher) and it took a quite long time to iron out the bad habits, wrong approaches or unnecessary clumsiness.
Answer: You are not actually talking about online lessons here but offline lessons: the teacher has recorded a lesson which you play back without interaction.  Also it is not an individual lesson but applies to everybody equally.
As such, it will not address any problems or mistakes particular to you.  Your "in the middle of nowhere" situation does not apply to actual online lessons (via videoconferencing) so you should not restrict your options to working without a teacher altogether.
Comment: I'm talking about courses where there is no instructor in which I interact. Let me clarify my question.
Comment: If correcting bad practices before they become bad habits is a significant concern, recorded lessons supplemented by occasional videoconference instruction would be advisable.
Answer: Not a good idea. You wouldn't learn how to fly a plane or operate on someone via online course. Studies say that playing a musical instrument involves more brain cells than flying a plane or performing surgery.
Comment: While you have a point, it would be best to include some additional thoughts for the answer to hold any weight.  One can certainly learn in a multitude of ways and there are drawbacks for some of them.  I would suggest adding specific things that would be a concern of learning online for this answer to be more potent.
Comment: Certainly there are disadvantages to learning anything on line compared to having a live instructor to critique your application of the lesson material.  However, your examples are so extreme they discredit your position.  Obviously if you are do it wrong as a surgeon or pilot, people might die.  I don't think anyone has ever died trying to play the flute.  You might consider some more credible analogies.  I like your mentions of the brain cells involved.  Can you explain in more detail why that fact makes on line learning more difficult?  That would be an interesting angle.
Comment: One can learn most of what is necessary to get a pilot's license from Microsoft Flight Simulator with decent input peripherals, so that's definitely not a good example for the assertion that learning through an on-line course isn't practical.

Learning an instrument online


Fazer PHP imprimir o resultado da classe Fatorial

Question: <?php
    class Fatorial {

        function calcular(){

            $fat = $_GET['fat'];
            $resultado = 1;
            for($i = $fat; $i >= 1; $i--){
                $resultado *= $fat;
                $fat--;

                return $resultado;
            }
        }
    }

    # Instancia a classe Fatorial()
    $c1 = new Fatorial();

    # Executa a função
    $c1->calcular();
?>

<!DOCTYPE html>

    <meta charset="UTF-8"/>
    <title>Questão 2</title>

    <form method="GET" action="">
        Digite um número:
        <input type="text" name="fat">

        <input type="submit" value="enviar">
    </form

Answer: Não é a resposta da pergunta, mas pode ser uma alternativa para quem buscar por fatorial.  Uma forma bem simples: com   gmp_fact
exemplo - ideone
if (isset($_GET["fat"])){

    if ($_GET["fat"]==0){
        echo 1;
    }else{
        $fatorial = gmp_fact($_GET["fat"]);
        echo gmp_strval($fatorial);
    }
}

Answer: Para números pequenos pode simplesmente fazer:
array_product(range($numero, 1));

Se quer o 8! o range() irá criar [8,7,6,5,4,3,2,1] e o array_product irá multiplicar todos eles, resultando em 40320.
Teste isto.

Criar uma classe para isto acredito que seja desnecessário, entretanto:
class Fatorial
{

    function calcular($numero)
    {

        return array_product(range($numero, 1));

    }

}

Logo:
$resultado = 1;

if (isset($_GET['fat']) && ctype_digit($_GET['fat']) && $_GET['fat'] > 0) {

    $fatorial = new Fatorial();
    $resultado = $fatorial->calcular($_GET['fat']);

}

Teste isto.

Caso precise de números grandes utilize o bcmath, uma vez que o seu resultado é por string.
Answer: Seu código atual existe problemas de vários tipos, um é $_GET['fat'] que é adicionado diretamente no método da classe, isso torna o código obsoleto, o correto é passar uma variável no primeiro paramento do método tornando o código útil a qualquer momento, outro ponto é o return dentro do for, o return nesse caso deve ser a última linha, trazendo o resultado corretamente quando todas as interações forem concluídas e por fim faltou dar um echo para trazer a saída do resultado.
Dessa forma tem o efeito esperado com todas as correções:
<?php
    class Fatorial
    {
        public function calcular($fat)
        {
            $resultado = 1;
            for($i = $fat; $i > 1; $i--)
            {
                $resultado *= $fat;
                $fat--;
            }
            return $resultado;
        }
    }
    $result = "";
    if (isset($_GET['fat']) && is_numeric($_GET['fat']))
    {
        # Instancia a classe Fatorial()
        $c1 = new Fatorial();

        # Executa a função
        $result = $c1->calcular((int)$_GET['fat']);
    }

?>

<!DOCTYPE html>

    <meta charset="UTF-8"/>
    <title>Questão 2</title>

    <form method="GET" action="">
        Digite um número:
        <input type="text" name="fat">

        <input type="submit" value="enviar">
    </form>
    <?php
        if ($result != "")
        {
            echo $result;
        }
    ?>

Comment: Acredito que se você explicar que o problema era somente armazenar o retorno do método e a validação da existência do valor (se entendi bem), melhorará bastante a resposta. É aquela coisa: sempre bom descrever o que acontece no código ou, nesse caso, a correção que foi feita. Para um usuário leigo, essas mudanças podem não ser tão claras.
Comment: @AndersonCarlosWoss feito!


Does 'lvremove' destroy data?

Question: I assign a LV for each vm guest. When deleting a vm, I remove the corresponding lv running 'lvremove'. But is it necessary to destroy the data before running 'lvremove'? Does lvremove do the work of wiping out old data?
dd if=/dev/zero of=/dev/sda bs=1M

In other words, is it possible for a new vm guest to dig out previous vm guest's data? I heard people can use the following command to dig out old data.
cat /dev/vda | strings > /dev/shm/dump.txt.

Answer: No, lvremove only destroys the metadata identifying the logical volume and the specific extents which it used. It is possible to recover the data that used to be in the volume, if specific steps were not taken to destroy it.
This is a little better if you are using LVM thin provisioning. In this case, a newly provisioned LV will use no space at all, and thus reads from it will all return zeroes until something is actually written to it, in the process destroying the previous data. If your primary concern is VMs being able to read data from previous VMs, this should be sufficient.

Does 'lvremove' destroy data?


proving Riemann-Lebesgue lemma

Question: I have looked at proofs of the Riemann-Lebesgue lemma on the internet; all of these proofs use the technique of Riemann integration and making step functions.
E.g.(https://proofwiki.org/wiki/Riemann-Lebesgue_Lemma)
But if we know Parseval's identity (or Plancherel's identity for Fourier transform)
then, can I use
$$
\sum_{-\infty}^\infty |a_n|^2 = \|f\|^2 = M<\infty
$$

then the tails of the sum is very small, $a_n \rightarrow 0$ as $n \rightarrow \infty$?
Answer: No you cannot, Parseval's Identity works in Hilbert spaces, e.g. $L^2$ but not in a general Banach space e.g. $L^1$.
Comment: @mnmn1993 If you have $\infty=\infty$ in Parseval's identity, this does not help you prove that the terms go to zero.
Comment: but the only condition for Parseval's Identity is the Integrability??
Answer: This shows RL Lemma for $ L^2 $ then we can extend it to $ L^1 $ by density.
Answer: There's a really nice proof that "avoids step functions".
With a $u-$substitution you can conclude that $$ \hat{f}(\xi) = \int_{\mathbb{R}} f(x)e^{ix\xi} dx
\\
  = \int_{\mathbb{R}} f(x + \frac{\pi}{\xi})e^{ix\xi}e^{i \pi}  dx \\
  = - \int_{\mathbb{R}} f(x + \frac{\pi}{\xi})e^{ix\xi} \ dx $$
By averaging these two representations of Fourier transform, we obtain  $$\hat{f}(\xi) = \frac{1}{2} \int_{\mathbb{R}} (f(x) - f(x + \pi/\xi) ) e^{ix\xi}  \ dx $$
Since $|e^{ix}| = 1$, we can then conclude that
$$\hat{f}(\xi) \leq \frac{1}{2} \int_{\mathbb{R}} |f(x) - f(x+\pi/\xi)| dx $$
Letting $\xi \to 0$, finishes the proof assuming we can interchange limits and the integral. We can, but the proof of why (at least the ones I know) still require that step function type argument which is why I put "avoid step functions" in quotes.

proving Riemann-Lebesgue lemma


Adicionar elemento em JList

Question: Essa ação de um botão serve para adicionar o caminho de um arquivo em um JList:
 private void bArquivoActionPerformed(java.awt.event.ActionEvent evt) {

    JFileChooser fileChooser = new JFileChooser();
    fileChooser.showOpenDialog(this);
    File arquivo = fileChooser.getSelectedFile();
    listaarquivos.add(arquivo);
    tArquivo.setText(arquivo.getPath());
    DefaultListModel modelo = new DefaultListModel();
    tListaArquivo.setModel(modelo);
    String l = arquivo.getPath();
    if(listaarquivos.size()==1){
        modelo.add(0,l);
        index = 1;
    }else{
        modelo.add(index, l);
        index++;
    }
}

Ele mostra o seguinte erro quando o botão é chamado pela segunda vez e assim ele vai para o else:
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 1 > 0

Comment: Por favor, forneça um **[mcve]** para que seja possivel executar o código e testar o problema.
Comment: Por quê não remove esse if/else e deixe o java cuidar do tamanho da lista para você, utilizando `modelo.addElement(l)`?
Answer: Há dois problemas aqui:

O primeiro é a sua variável index ser utilizada desse jeito. Você não precisa dessa variável, basta usar o método addElement(E). E também não precisa desse if.
O segundo é que você está sempre criando um novo DefaultListModel ao invés de usar o já existente.

Além disso, recomendo a você usar os tipos genéricos adequadamente.
Para arrumar esses problemas, primeiro, declare o JList assim:
private JList<String> tListaArquivo;

E se possível, no construtor da classe que tem o método bArquivoActionPerformed ou em algum outro lugar que configure o JList criado, coloque isso:
tListaArquivo.setModel(new DefaultListModel<>());

E então, tente isso:
private void bArquivoActionPerformed(java.awt.event.ActionEvent evt) {
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.showOpenDialog(this);
    File arquivo = fileChooser.getSelectedFile();
    listaarquivos.add(arquivo);
    DefaultListModel<String> modelo = tListaArquivo.getModel();
    tArquivo.setText(arquivo.getPath());
    modelo.addElement(arquivo.getPath());
}

Também apague a sua variável index.
Finalmente, o uso de notação húngara não é recomendado. Notação húngara é a prática de prefixar nomes de variáveis com informações sobre o tipo ou o contexto no qual ela é declarada, coisa que as convenções de código do Java desencorajam bastante. Assim sendo, ao invés de bArquivoActionPerformed, use botaoArquivoActionPerformed. Ao invés de tArquivo, use textBoxArquivo.

Adicionar elemento em JList


Which measure for inter-rater agreement for continuous data of 2 raters about multiple subjects in multiple situations?

Question: I've considered measures like Cohen's kappa (but data is continuous), intra class correlation (reliability, not agreement), standard correlation (will be high when one rater always rates consistently higher than the other rater)... but none seem to represent what I want it to.
I need a measure that will show % agreement between two raters, that have rated videos of multiple subjects in multiple situations and this in 8 different experiments.
So for example, for experiment 1 rater 1 rated 12 subjects in 3 situations and rater 2 did the same, for experiment 2 rater 1 rated 14 subjects in 4 situations and rater 2 did the same. And so on. Which measure would then be adequate to test how much the raters agree over all these 8 experiment? Or just per experiment, so that I can take calculate an average of the 8 values.
I'm sorry if this is an abundant question, but I've never been trained in these kind of statistics and I get completely lost searching the internet for an answer. I need to be sure that this measure is good for my data as I need to use it in my thesis.
Experiment 1, situation 1:
<code>    Rater 1    Rater 2
Subj1 13         12

Subj2 85         71

Subj3 67         45
...   ...        ...
</code>
Experiment 1, situation 2:
<code>    Rater 1    Rater 2
Subj1 76         90

Subj2 62         51

Subj3 51         51
...   ...        ...
</code>
Data looks like this with per experiment a number of subjects that are rated from 0 to 100 (= % freezing) in 3 (or 4) different situations by 2 raters (always the same raters). You can find an example excel file here (might be more clear): dropbox link
Thing is, if rater 1 says 76 and the other says 77, that's good, it's normal that it won't be perfectly the same value, but if it's close, it means that the raters kind of agreed. So continous data, the values go from 0 to 100 and are not categories or anything. If the value by the 2 raters is not exactly the same, that doesn't necessarily mean that there's no agreement: the more distant the values are from each other, means that we had less agreement, the closer they are, the more agreement the raters had.
Comment: To me, it looks like a categorical data, not continuous data. Can you post a minimal hypothetical reproducible example/data?
Comment: I edited the post to include an example. Thank you for helping. I also included an example excel file via a dropbox link, because it might be more clear that way.
Answer: If the categories are considered predefined (i.e. known before the experiment), you could probably use Cohen's Kappa or another chance-corrected agreement coefficient (e.g. Gwet's AC, Krippendorff's Alpha) and apply appropriate weights to account for partial agreement; see Gwet (2014). However, it seems like an ICC could be appropriate, too. I do not really understand what the "situations" are all about.
Gwet, K. L. (2014). Handbook of Inter-Rater Reliability. Gaithersburg, MD: Advanced Analytics, LLC.


Why does my process stop when run in background?

Question: I am running a simple PHP script on a CentOS 6.5 with php5.3.3
#!/usr/bin/env php
<?php
    echo "hello"."\n";
    return 0;
?>

My issue is that if I do ./testscript, it runs fine, if I do nohup ./testscript &, it runs fine, if I do ./testscript < /dev/null > /dev/null & it runs fine (it is the same without the output redirection).
But if I do ./testscript &, the script is stopped (and there is no output) :
[1]+  Stopped                 ./testscript

From what I understand, this is because php is expecting some input from STDIN. But the question is why ? As you can see, there is nothing requiring some input in this simple script, and I didn't have this behavior on my php5.4 on Debian. Does this change in behavior comes from php version or OS ?
And why is it this way ? Is there a way to change that and to allow me to run script in background without having to add /dev/null as STDIN ?
Thank you !
Comment: Related (CLI version was built with readline included): http://stackoverflow.com/questions/8194755/php-script-wont-run-in-the-background
Comment: Try doing something like `./testscript > output.log 2>&1 &`.  It should stop, but at least you can see what it output before it crapped out.
Comment: @hellcode: -1. that's how  shell script MUST be constructed. no shebang, no `./foo.php`-type invocation.
Comment: @Mr.Llama: output.log is empty this way. And the script stops because of STDIN..
Comment: Related: http://stackoverflow.com/questions/17912137/command-line-script-run-in-background-goes-in-stopped-state
Comment: @hellcode - Out of curiosity, why does the `nohup` version work but not regular `&`?  Does nohup silently feed `/dev/null` as input?
Comment: @hellcode : Thanks, this is exactly what I wanted to know !! :)
Answer: Your program does nothing but printing something and terminating with return 0 (sure you don't mean exit()?). After the code is executed the php interpreter has nothing to do any more and simply signals to the shell "Hey Buddy! I am done! You can notify the user!" Calling it with & simply tells the shell: "Run this command in background." Which it does. Exactly once.
In order to have your program run indefinitely, it has to actually run indefinitely, too.
<?php
  while(true) {
    // Doing something useful
    sleep(5);
  }
?>

With nohup, the "program" (the php interpreter, in this case) is basically prohibited to terminate - but it will do not much any more. As for the redirections - they will actually target the php interpreter, which will wait for further input, which is not coming because /dev/null does not emit anything.
Comment: He doesn't indicate that he wants his script to run forever. `nohup` doesn't prevent (or prohibit) the program from exiting, it prevents it from being killed because of a hangup signal. His question is *why* is php waiting for input. He hasn't asked it to do that.
Comment: Actually, what else should be the reason to have the input/output redirection? Maybe I simply don't get the question.
Comment: He was indicating various ways he has run the program such that it worked. To illustrate the various things that solve the problem he is having... namely that his script seems to be waiting on stdin and he doesn't know why.
Comment: @Markus W Mahlberg: as Etan says, I don't want the script to run forever. And I can use return or exit or nothing, my issue is the same : the php script stops before doing anything (it doesn't echo my hello). When I say "stop", I mean the script has the status "stopped" (T in ps aux), which kind of like a pause.
Comment: Which I explained - when a stdin is opened for php, it waits for more things to come after the original script is run. Try it with `php << EOF`...
Comment: @user3017110: Ah, now I get it. I can reproduces the stopped problem with PHP. The problem might be related to http://unix.stackexchange.com/questions/67645/why-do-background-jobs-hang-depending-on-the-size-of-the-output When I use a simple wrapper script like `php -f $@ &`, everything works as intended.


Coded ui- How to update properties of object in UImap.uitest file which has changed in application?

Question: Coded ui- How to update properties of object in UImap.uitest file which has changed in application? for example a window which has version of software changes with every build. The issue is if I try to record anything on new version of software it creates new objects in UImap and the whole object tree again. This makes UImap too huge adding duplicates of objects with slightly different property.
Answer: You don't want to update the properties to latest, but make the property values dynamic.  Just updating the properties will mean more work the next time your code changes.
Also, try to only use properties to search on that do not change between application runs/versions.  Example, a class property will likely remain static between runs, while the title of your parent window may change based on the version number.  Check out this article to see how to modify the recording's search properties to fit your needs, specifically the section on modifying UI action properties.
Another method to look into would be to create the objects and methods yourself using C#.  By adding controls yourself to the uimap.cs partial class of the .uitest, you have can specify at design time what properties and values that Coded UI uses to execute your tests.


Theme Views exposed filters, how to add count?

Question: For example in the case of filtering by taxonomy terms, I would like to add the node count next to each term in the exposed filter block. Already using Better Exposed Filters module as it allows to use checkboxes instead of select list.
Is there a way to do this? I can make a nice list of the terms with node counts using aggregation, but I can't think of an easy way to use ajax that way. :-)
Answer: What you are asking for is what is called faceted search.
If you want to have this feature you should think about using a search database that supports this, like Apache Solr. The problem is that it otherwise is going to be very heavy and complex to make, especially with views making the query for you. If you were to make this feature yourself with MySQL, it would probably be easier to code the entire page yourself, and add the facets for the terms in your custom form.
In Drupal 7 the search api module comes with support for Apache Solr and can do facets on both MySQL and Solr. It also have views integration.
For Drupal 6, you can use the Apache Solr Search integration module, which creates an API integration with Solr, making it easier to create facets with Solr. Use this would probably require that you custom made the entire form.
Comment: Note that the D7 version of the Apache Solr module leverages Facet API, so the ability to tweak facet displays has improved.  For example, you can also expose facets as form elements to help build search page forms.  Search API is moving towards Facet API as well.
Comment: Thank you, Apache Solr is the solution. Now I just have to figure out why Display Suite does not want to apply the custom view mode on the search results... (Drupal7)
Comment: So can you explain how to do part where you add the count to exposed filters?


How do you get DRUPAL_ROOT when using it in a separate php file?

Question: It has been covered many many times on several sites, explaining how to define DRUPAL_ROOT and bootstrap the page (whatever that actually means). However no one has ever said how to use it in a separate PHP file.
I am trying to use a php file as my data layer in a custom module. However when I use define('DRUPAL_ROOT', getcwd()) it comes back with the directory of the module (as expected).
If I use $_SERVER['DOCUMENT_ROOT'] it comes back with the www HTML folder and not my drupal install folder.
If I add .base_path() it doesnt know what the hell that is!
I can't just had code it because it's going to another IT team and I have no idea what their file structure is like.
Please, can anyone help! I am going insane!!
Its just a standard php file with some db_query's in. This really can't be as hard as I'm making it, can it?
Comment: Are you making a module or trying to have a completely separate php page that accesses Drupal in some way?
Comment: It's supposed to be a module that exports data from the database to Microsoft Word. However my manager insisted that I break all of the code out into separate php and inc files so there is nothing in the .module file.

Would this make a difference as to why it doesn't understand DRUPAL_ROOT?
Answer: Why not use DRUPAL_ROOT instead of trying to define it in your php file?
DRUPAL_ROOT is already available at this point and it contains the path to your Drupal installation.
For example:

watchdog('testlog', DRUPAL_ROOT . 'test');
Comment: Thanks @sshrestha . However I tried using just DRUPAL_ROOT as: require_once DRUPAL_ROOT. '/includes/bootstrap.inc'; and it gave the error: Warning: require_once(DRUPAL_ROOT/includes/bootstrap.inc): failed to open stream: No such file or directory. Not sure if I am doing something wrong or if it makes a difference that it is not in the module file. –
Comment: @James I hate to be pedantic, but if what you typed in is verbatim command, then it is a syntax error. It should be require_once(__ROOT__.'/config.php');
Just want to make sure its not something that simple before thinking too far ahead.
Comment: Just tried require_once(ROOT.'/config.php') and that doesn't work either, as well as (DRUPAL_ROOT.'/config.php')
Answer: You need to define the DRUPAL_ROOT constant to point to the folder where your drupal installation is (in other words, on same folder where the index.php is located)
The bootstrap phase that you need load will depend on what do you need to do on your separated php script (db queries, session handling, multilanguage, ...).
On this answer you can see a small example on what I think you are looking to implement.
If you don't know where is going to be installed the Drupal site on other environments, you could use a relative path to define it, for example, if your script it's located in a module with this path:
<code>sites/all/modules/custom/my_module
</code>
And your site has the same architecture on the other environments, you could set the DRUPAL_ROOT like this:
<code>$drupaldir = realpath('../../../../../');
define('DRUPAL_ROOT', $drupaldir);
</code>
It's not elegant but it should work on any environment no matter on which folder is the drupal site.
Comment: If you have access to one of those sites as an admin user, you could go to admin/reports/status/php and check the DOCUMENT_ROOT value.
Comment: Thanks @gerzenstl, however they have used "define('DRUPAL_ROOT', '/var/www/clients/client1/web15/web');" to define where the index.php is. I have done this and it works fine but as its going to another IT team that deals with many many drupal sites, I dont know what their file structure is like and therefore how to define it.

I would ask them but they seem to get really stroppy if you ask them what seem to be really stupid questions.
Comment: It's not a stupid question to ask about where is located the index.php of a Drupal site/multisite installation. It's very hard to guess if all those sites are on a same location on the structure folder.


GIF images in Chrome loading slow and/or other problems

Question: I am experiencing problems with Chrome and animated .Gif in which they frozen, are slow loading, show screen tearing animations and etc.
Answer: 1- Type chrome://plugins into the address bar
2- Click the  button on the right side to expand the plugins.
3- Look for the PPAPI PepperFlash plugin.

4- Click Disable
If you already have the official Adobe version of Flash installed, it should show up right under the pepperflash plugin listing

5- Leave this one enabled.
Otherwise go download the official one from adobe (http://get.adobe.com/flashplayer/)
6- Clear the cache. Restart chrome.
Note: Pepperflash re-enables itself after Chrome updates so look out for that. Seems that this bug is fixed in the Chrome dev builds, so it might be fixed in an update sooner or later.
Source: http://www.neogaf.com/forum/showthread.php?t=502191
Comment: It is not a great practice, to ask your users to install plugins.
Comment: Agreed. This is supposed, though, to be a temporary solution -it works for me for the time being and none of our clients has of yet complained about this-, until someone else can show a better way.
Answer: Are you using the animated GIFs as a background image on an element? Chrome is known to have problems with this. If you can find a way to use them in the actual markup, Chrome will serve them fine.
Answer: If you use AJAX requests on the page and these are synchronized ( async: false in jquery ), this can be happening in opera/chrome.
AJAX is defaultly asynchronous, so if you did not explicitly state async: false, you do not have to state async: true and this answer might not help you.
Try deleting the line containing async: false.


Postgresql DatabaseError column with django

Question: I am trying to find a solution to this error I keep getting:

column posts_post.slug does not exist
LINE 1: SELECT "posts_post"."id", "posts_post"."title", "posts_post"...

Does anyone know what might be causing this?
Here is the full error output: http://dpaste.com/813336/
<code>    from django.db import models
    from django.contrib.auth.models import User
    from datetime import datetime

    class Category(models.Model):
    name = models.CharField(max_length=60)
    def __unicode__(self):
        return self.name

   class Tags(models.Model):
    name = models.CharField(max_length=60)
    def __unicode__(self):
        return self.name

   class Post(models.Model):
    title = models.CharField(max_length=120)
    slug = models.SlugField(max_length=120, unique=True)
    description = models.TextField()
    body = models.TextField()
    published = models.DateTimeField(default=datetime.now)
    categories = models.ForeignKey(Category)
    tags = models.ManyToManyField(Tags)
    def __unicode__(self):
        return self.title
    class Meta:
        ordering = ['-published']
    def get_absolute_url(self):
         return "/%s/%s/%s" % (self.published.year, self.published.month, self.slug)
</code>
Answer: Did you add the SlugField later? If so, a syncdb does not update existing database tables. Delete the entire table and re-do the syncdb.
Answer: The error is quite simple - you don't have the column slug in the given database table. If you added it later in the model, syncdb doesn't modify the table (this operation can not be done automatically). For this purpose, use the South application which is a must have application for Django.


Is it possible to do a linear regression without the individual samples

Question: Just curious if I have only categorical predictors and a continuous response variable, is it possible to do a regression using only summary statistics of each possible combination of my indicators (e.g, sum, sum of squares, n, etc)?
Comment: Yes, it's possible with what you have.  How you do it depends on the model you want, so let me just point out that you have a "full" model: your estimates of mean response (which can be obtained by dividing the sum by $n$ for each combination) give the most detailed regression possible of the response on the categories. This kind of modeling is usually done with formulas from Analysis of Variance.
Comment: What exactly do you have? You'll need some kind of data about the relation of the response to the predictors....
Answer: As whuber points out, I may well have misinterpreted the question; consequently I'll edit to answer it two ways. [I'm still making some assumptions here relating to the form of the model, so there's still some potential room for misinterpretation even now.]

If "in each category" means "at each combination of factor levels" (cells in a k-way table, for k categorical predictors), then you actually only need the counts and the sum of the y's at each combination (in each cell) to get the coefficients. (Sums of squares of y's would be needed for some other things, as suggested below.)
If by "in each category" you mean "for each categorical variable" then that would consist just of marginal summaries, and
marginal summaries (sums and sums of squares) are not sufficient.
Here you need sums of cross products as well; $x_i'x_j$ (across all pairs of predictors) and $x_i'y$. (This is equivalent to finding the counts and sum of y's in each cell in 1. above)
With those as well as sums and sums of squares (which are just $x_0'x_j$ and $x_0'y$ for $x_0=\mathbf{1}$, in order to fit a constant term), you can form $X'X$ (a matrix whose $i,j$ element is $x_i'x_j$) and $X'y$ (a column vector with $i$-th element $x_i'y$, in both cases indexing from $0$ rather than $1$) and hence attempt to solve the regression problem (i.e. solve the system $X'X \hat{\beta}=X'y$).
This could then be done, for example, by forming the Cholesky decomposition of $X'X$ (don't attempt to directly invert $X'X$):
If $A=X'X$ and $z = X'y$ you're trying to solve $A\hat{\beta}=z$ for symmetric (and hopefully positive definite) $A$.

Form $A=LL'$ (other versions of Cholesky form $LDL'$ or $R'R$ or $R'DR$, but the basic approach is similar)
Solve $L \zeta=z$ for $\zeta$ by forward substitution
Solve $L'\hat{\beta}=\zeta$ for $\hat{\beta}$ by back substitution

You then have the parameter estimates
If you need things like $R^2$ or $s^2$ you'll also need $y'y$.
Comment: Did you notice that the question concerns *categorical* explanatory variables? All these extra statistics you are requiring are unnecessary--and can be computed from the sums, counts, and sums of squares in each category, depending on how the categories are coded.
Comment: It's possible I've been interpreting the phrasing of the question incorrectly (my answer does point to the fact that I found the phrasing ambiguous, giving what would be needed if it was taken one way). Let's assume for simplicity that the x's in my exposition are all 0-1 variables; then if by "in each category" the intent was "at every combination of factor levels" (which wasn't how I interpreted it --  I took it as 'for each categorical variable'), then yes, what I say to compute would have already been computed, since they'd just be the counts in each combination of factor levels ...(ctd)
Comment: (ctd) ...  but under that interpretation the sums and sums of squares of the x's in each combination of factor levels would be redundant -- they'd all just be the count (which is part of why I didn't interpret it that way) - you only need the count and the sum of y in each combination of levels (to get the estimates). I'll come back to clarify my answer to cover that interpretation, because on reflection I think you're right that it's the actual intent.
Comment: @whuber hopefully this addresses the question better; rather than noting the ambiguity and sticking with my original interpretation, I now cover both interpretations.
Comment: I may come back and add more details and a specific example


about PMI(pointwise mutual information) independence

Question: as picture shows it says A, B are independent which means P(A,B) = P(A)P(B).
then isn't pmi always 0? because log1 = 0?
what am i assuming wrong here?
Answer: That Wikipedia sentence is worded in such a way that the correct parse is somewhat ambiguous. Here's how I might reword the definition:

The PMI of $x$ and $y$ quantifies the discrepancy between the following two probabilities:

the probability of $x$ and $y$ under their true joint distribution, which is $p(x,y)$
the probability of $x$ and $y$ under the assumption that $X$ and $Y$ are independent, which is $p(x)p(y)$

So yes, if $X$ and $Y$ are in fact independent, then their PMI will always be 0. But the definition doesn't assume that this is the case.
Comment: i am not sure i understood what you said the original sentence said " assuming independence" .
and you said "doesn't assume that this is the case"
so we only calculate PMI only when X,Y are dependent?


Show that the set $A:=\{f\in{C[0,1]}: |f(t)|<1 \forall{t\in{[0,1]}}\}$ is an open set in $C[0,1]$ with the supremum metric.

Question: By definition, I need to show that every point in $A$ is an interior point in $A$. Do I go about this by showing $A'$ is closed? Please help.
Correction in the title: For all $t\in{[0,1]}$.
Comment: Assuming $\;A\;$ is closed won't give you a contradiction proof. For that you need to assume $\;A\;$ isn't open (which is **not** the same as being closed)
Comment: You mean $t\in[0,1]$ in the title.
Answer: Hint: $[0,1]$ is compact; what does this imply about the maximum / minimum values of $f$?
Given this, convince yourself that
$$\|f - g\| < \epsilon \implies \max_{t \in [0,1]} |g(t)| < \max_{t \in [0,1]} |f(t)| + \epsilon$$
Can you finish it from here?

Remark: Showing that $A$ is closed doesn't help at all, since open and closed are not opposites of each other.
Comment: We haven't talked about compactness but I'm guessing the minimum and maximum values of $f$ are $0$ and $1$ respectively.
Comment: @user121087 No information is given about the maximum and minimum values of $f$; for example, $f$ *could* be the constant function $1/2$. The relevance of compactness is the [extreme value theorem](http://en.wikipedia.org/wiki/Extreme_value_theorem) which implies that $f$ actually attains its maximum in $[0,1]$.
Answer: Show its complement is closed. Let $f_n$ be a convergent sequence such that $f_n(t_n)\geqslant 1$ for a sequence of points $t_n\in [0,1]$. Let $t_{n_k}$ be a convergent subsequence, guaranteed by Bolzano Weiertrass. I claim that if $t_0=\lim t_{n_k}$, then $f(t_0)\geqslant 1$. Since $f_n\to f$ uniformly, in particular $f_{n_k}\to f$ uniformly, so $1\leqslant f_{n_k}(t_{n_k})\to f(t_0)$.
Comment: Thank you. I'm not sure how this way involves the supremum metric though.
Comment: @user121087 It is crucial to prove $f_{n_k}(t_{n_k})\to f(t_0)$. =)
Comment: Ahh, of course. Thanks!


Does it make sense to do exam grades as an adult learner?

Question: I'm in my thirties; I've played acoustic guitar for about a decade, but recently took up "proper instruments" flute and piano as a beginner - playing from score, learning scales, etc rather than just bashing chords. I did do up to grade 3 classical guitar (in the UK) as a young child so I luckily can read music, etc.
I have been having semi-formal lessons and bought myself some ABRSM grade 1-3 books on both instruments.
I'd frankly feel a bit of a fool turning up as a grown man, to do a grade 1 piano exam, and I wondered if there is any point doing grades other than for a sense of achievement. If I work through pieces and grade requirements, is there a benefit to taking the exams?
Do many adults take the grade exams, especially the very low grades?
Comment: [ABRSM's take on the subject](http://gb.abrsm.org/en/news/article/adult-learners/187/)
Comment: When my kids started learning to play in the local brass band, as is very common here in South Germany, I decided to learn clarinet. After a year the teacher said all his students had to do D1, which is theory and practice for brass band. So I enrolled and did it too. I had the advantage over the little kids of being disciplined at learning, but of terrible nerves at playing. In the exam I was the oldest person in the room. The examiners were very excited and complimented me on my courage. Well, I went back and did D2.
Comment: The experience was very good for me, and the structured theory material has been helping me ever since. They do have older students - maybe 10 a year - and recently they have started offering D courses just for adults.
Comment: My aunt was a concert-grade pianist via superb individual teachers, but had never completed any formal courses. When she went into piano teaching after two or three decades as an accompanist and repetiteur, she took the top couple of grades and the licentiate examination to qualify as a piano teacher.
Answer: I organise an exam centre for guitar (electric/acoustic/classical) and bass exams. Whilst 80% of candidates are younger than 18 or so, that leaves 20% adults. Most of them come with a bundle of nerves, but I see them for the next, and the next,and so on. Frequently they say "I don't know why I'm doing this", but the main real reason seems to be that they see it as a thorough, structured way to get good on an instrument.It somehow focuses them in their practice, seeing the goal.
Other instruments will have the same regime, so don't be concerned that you're following a 6yr old into the exam room. You will be judged on the performance, and no-one's going to think 'he should play better than that 6yr old, 'cos he's older'. The exam is not supposed to be subjective. Trouble is, most folk stop 'doing exams' in their late teens, so after that, they get out of the habit. Kids are doing tests and exams almost on a weekly basis, so for them, it's just another pesky exam.For adults, it's something they thought they'd left behind!
Give it a try. You actually don't need to go through each and every one. Start where comfortable, and see how it goes. Insist your teacher shows you exactly what will happen in those 10-15 minutes.
Also consider other exam boards - Trinity, LCM (RGT), etc.You may enjoy one better than another, but the standard of playing ought to be very similar. And the certificates are great for covering up dodgy wallpapering...
Comment: @anatolyg - for the next exam grade, either 4 mths, 8 mths or a years time.
Comment: What do you mean by "see them for the next"?
Answer: After ten years with the guitar you'll have become quite comfortable with the instrument, and will have developed some musicianship. Naturally it's humbling to take up another instrument and find your fingers tripping over pieces of music that you could probably pick out on guitar while standing on your head.
Feel humbled, but don't feel foolish. Relish being a beginner! If you think grade 1 would feel like an achievement, do grade 1. Your teacher will understand your situation, the examiner won't care how old you are, and you don't have to tell anyone else. I knew a violin teacher who was an examiner for ABRSM, and he told me that it always gave him a real buzz to see an adult beginner. He had nothing but admiration for anyone who takes up an instrument later in life.
That being said, if I were you I'd take a look at the grade 5 syllabus. The music starts to get a little more interesting at this stage, and you might find that fact is enough to help bridge the bigger gap between where your technique is now, and where it needs to be to play at that level. I did all the violin grades as a kid, took up piano at 30, and did grade 5 after about a year and a half.
Comment: Interesting. With piano and flute I'm so far finding G1 is appropriate since I have to get to grips playing two lines at once, and learn how to get the darn sounds out, respectively. But it would be nice to be able to skip quickly through earlier grades if possible :)
Comment: How long have you been learning piano and flute?
Comment: A few months, not practicing daily but at least a few times a week - I can play almost the first two octaves on the flute but having to learn the bass clef is a pain on the piano!
Answer: I've just turned 60. I did piano, clarinet and music theory exams ten years ago. I've started playing the trumpet and loving learning a new instrument. For one thing the trumpet is much more reliable that the clarinet which I use for busking. I like doing exams and I'm planning on doing the grade 1 trumpet exam later this year. As far as I know there are no restrictions on the age you can do exams at.
Answer: Taking certificates is generally always good, unless you are not aware about requirements (then the failure might bring unneeded disappointment). Check that is expected, and if you think you can do - then why not? This may help to meet new interesting people!
Comment: I talk about taking exam as a process, not if to show the certificate later or not. Preparing for exam is always good for learning.
Comment: @Mr. Boy-You may think you can play grade 1 pieces but unless someone with the qualifications to grade your skills agrees then it is just an assumption on your part. Granted, for many people their own perception may be enough. But for others, tangible proof of progress helps keep them motivated and being able to pass "tests" is a form of tangible proof.
Comment: I just find the idea of proudly showing my Grade 1 piano certificate to anyone a bit ridiculous... if I know I can play grade 1 pieces isn't this enough?


Create referral url for user and add UID to hidden field when url used

Question: I need to create referral url for authenticated user. This url should be url for webform, and it should include user UID.
When user shares this url and someone uses it to fill webform it should set UID to the hidden field in webform - so admin can see whose referral url was used.
How to create this url?
How to set referred user UID to hidden field?
Can someone point me to the right direction where to start implementing this?
Answer: If I understand the question correctly, you want something like:
h(tt)p://www.example.com/register?uid=25
where register is a webform that the incoming person can access?

I would start by creating the form at the correct location with all of the elements you want
use some javascript (or form override) to hide the relevant form item that will hold the uid
override the form submit function to assign the uid in the url to the hidden element

take a look at the documenation for webform, and the Drupal Form API for specifics.


Need help reading this music sheet

Question:
Complete newbie here, i've been handed this piece of music and im not completely sure how to read it. Can someone tell me how to read this piece and what is says?
i know it looks simple but im not that musically inclined. Thank you in advance
Comment: Key word to look up on wiki: tenor clef (1)  and octava (2) https://www.liveabout.com/8va-symbol-2701434
Comment: As always, http://www.dolmetsch.com/musicalsymbols.htm
Comment: @AlbrechtHügli when suggesting that someone look something up, it helps to spell it correctly: *ottava.*  The full phrase is *all'ottava,* meaning "at the octave."
Comment: @phoog  when correcting someone, be sure you aren't crossing language-specific spellings :-)
Comment: @CarlWitthoft "octava" is the correct spelling in Spanish, but it is not the source of the abbreviation.
Comment: phoog is right: I wanted to look up what OP could have done to find the answer: and I was looking up google just giving in 8va. (we use to spell both: all' ottava but the in swiss german we just say: octave). To add OP's question:
8vb = octava bassa (lower)
Answer: The first example uses 'tenor clef'.  Still in everyday use by orchestral trombonists and cellists.   Look at it as an ornate letter C, wrapped round the 4th line - it indicates that line is middle C.  So the note is G above middle C.
I guess I don't have to explain the bass clef?  The note is A above middle C (count up the 'ladder' of ledger lines). The 8va above tells us to play it one octave higher.
Answer: 8va means the note so notated to be played one octave higher than shown.So it's going to be the A normally written on the first ledger line above the treble clef. 15ma means two octaves higher than shown; 8vb means an octave lower than shown (but is actually redundant, as 8va placed in the right position (up or down) does the proper job.
Ostensibly, since the A note is actually written on the bass clef, if it's for piano, it's played with l.h. Although I suspect it's written for double bass.
The first example is a strange sign that's moveable. Its centre denotes middle C So counting upwards, the note shown is G - the G above middle C. That sign usually has its centre on a line, and can be moved in order to accomodate certain instruments' ranges.
Comment: I thought two 8vas higher would be 16 higher, but correct would be 15ma (quindicessima).
Comment: In piano music, hands are not assigned to clefs. Generally, in beginner music, the LH plays in the bass clef and the RH plays in the treble clef, but that is only until students are used to reading the clefs and know where all the notes are located on the piano. I read two treble clefs or two bass clefs quite often, and I also have played music written on a normal Grand Staff in which one hand crosses the other and plays notes in the other clef.
Comment: @HeatherS. - that may be the case, but I'd say that it's generally the case. All the stuff I have to play is written in two staves for the purpose of which hand plays which. Obviously two treble staves mean l.h. plays treble - but even then, would you agree that l.h. plays the lower? I'm putting a figure of >90% on music that has treble/bass clefs and each hand plays its appropriate clef.
Comment: Although they are not moved in practice in modern times, the F and G clefs are also movable, and were used as such in the renaissance and baroque periods.  Also, *8vb* is a spurious 20th-century invention by people who don't speak Italian; actually "8va" means "at the octave" without regard to direction, which is indicated by placing the notation above or below the note, and the notation for two octaves is *15ma,* not *15va.*
Comment: @phoog - points taken, edited accordingly. Thanks.
Comment: @Tim, yes I would say that LH plays the lower clef of a Grand Staff (as indicated by the brace.) I would leave it at that. I play way too much music where I am playing LH in treble clef to say that it is "generally so" that LH plays bass clef. For beginners, yes. But once one is beyond intermediate music, anything goes. I very often play music that is switching clefs in the middle of the piece. It just requires more effort to "fix" the explanation later on as to why the LH is not sticking to bass clef when it is just as easy to be more accurate from the beginning.
Answer: Let's assume you know to read the treble clef with G on the 2nd line and middle C on the 1st ledger line below the staff.
The clef we have at the left end of the 5 line system is an old clef  (tenor clef) assigning that C is on the 4th line (lines are counted from down to up).
You can think this 4th line as a the broken line (ledger line) of the middle C and cut the 3 lines below and add them on the top of the system. So the 4th line of C becomes the ledger line, the 5th line becomes the 1st line (E) and the note you are asking is om the 2nd line (G).
If you know to read the Bass clef you can progress analog: imagine this clef is on the 1st ledger line above the staff: 4th line = 1st ledger line (middle C), 5th line = 2nd ledger line (E) etc.
Your second example is answered by Tim. There's nothing to add (to find more information look up 8va, clefs, tenor clef and also  alto clef - where the C-clef is a line lower and the G will be on the 1st ledger line above the system.) btw. The dotted line behind 8va assigns how long the passage has to be play an 8ve higher, sometimes they write loco when the dots end and you have to play local again.
Looking up 8va I found this link:
https://www.8notes.com/glossary/8va.asp
Help for reading C-clefs: draw a staff system on a transparent film and lay the middle C (ledger line) over the line with the C-clef.
Comment: A is on the 2nd ledger line below the treble clef.
Comment: @ Heather : I don't understand your objection. What I am missing?

Need help reading this music sheet


Quadratic effect in OLS regression

Question: I am currently trying to do an OLS regression using data of online product reviews and I have two questions:

Do I have to use both, the linear and the quadratic effect in the model or is it also okay to only keep the squared variable in the model? I read that I have to use both, but I do not really understand why. So why should this be like this?
I am doing a regression with a helpfulness score of online product reviews as the dependent variable and the star rating of the reviews (integers between 1 and 5) as an independent variable. I would like to incorporate a squared effect, because I hypothesize that 1 and 5 star ratings are more helpful than moderate reviews (e.g. 3 stars). When I just square the star rating I get 0, 1, 4, 9, or 25 as possible values for the squared variable. However, to me it makes much more sense to first subtract 3 from the rating and then square the variables, because this better reflects the hypothesis that the extremer a rating the higher its helpfulness score. Now, I get 4, 1, 0, 1, or 4 as possible values for the squared variable. Would it make sense to do this?

Thanks for your answers!
Answer: You don't have to use a linear term to use a quadratic, but it's usually a good idea. The only situation I wouldn't use it is when your theory tells you that you have a quadratic process. For instance, if you somehow are measuring kinetic energy as a function of speed, then there's no linear term in theory:
$$e=m\frac{v^2}{2}$$
These are rare cases when there's no need for linear terms. Otherwise, it's better to keep them. If you don't have a solid theory, keep them.
Comment: +1. To make this even more explicit the principle is that (in more statistical notation) $y = bx^2$ implies that $y = 0$ when $x = 0$. Not knowing that to be true as a matter of principle usually excludes this square-only model in practice.
Answer: In my experience, I would say yes you would always adjust for lower level terms when fitting polynomial trends. This is the approach that is advocated in most of the biostatistics textbooks I've encountered. The reason for this is that the terms are guaranteed to have the correct interpretation. For instance, if you omit a linear (first order) term when fitting a quadratic effect, it is not guaranteed that the interpretation of the coefficient is the slope of the quadratic trend curve. You are constraining the fit so that the slope of the fit through the origin is 0. But when on Earth are we so confident that this is the case? Small measurement calibrations that bias or offset measurements by a single unit can catastrophically attenuate a quadratic slope. Relative to the small amount of power we spend to estimate the linear term, I advocate for using it always.
With respect to your second point, this argues all the more for including the linear term. I agree centering the value on 3 is nice because it gives a 0 and 5 star rating the same influence by symmetry (but the hypothesis that a certain rating is more "helpful" depends on what you estimate. You might estimate a negative quadratic trend on 3 star suggesting that moderate reviews are the most helpful... that's the point about being agnostic with statistics).
Comment: When on Earth? In some cases when it's the trajectory of a projectile under gravity. But yes, I strongly agree.

Quadratic effect in OLS regression


Function of a monotone map

Question: Suppose that I have a function $f(x)$ such that $f:\mathbb{R} \rightarrow \mathbb{R}$ monotone in $x$. Then consider a function $g(x)=\alpha f(x)$, $\alpha \in \mathbb{R}$. Can I say that also $g(x)$ is monotone in $x$ and that it is monotone increasing if $f(x)$ is montone increasing (decreasing) and $\alpha>0$ ($\alpha<0$)?
Comment: Yes you can say that.
Answer: Yes $f$ being monotone increasing means that $f'(x)\ge 0,\forall x\in\Bbb R$
Then $g'(x)=\alpha f'(x)\ge 0$ if $\alpha\ge 0$, and $\le 0$ if $\alpha\lt 0$.
So the property follows :)
Comment: How do you know $f$ is differentiable?

Function of a monotone map


Handling the potential risk of writing random bits to storage during power loss with RAID

Question: Is it possible for a power failure to cause some part of a machine to write one or more random bits to a storage device?
Someone proposed the following idea to address such a risk: create multiple partitions on a single disk which together form a single RAID1 array; then assemble multiple such arrays together as another RAID device; use that to store the file system.
My guess is that this is expected to work since random data cannot be written to each RAID member simultaneously. Perhaps there wouldn't be enough residual power for the drive head to seek forward and write the same random data in each member partition. If all goes to plan, the RAID member with the bad data would be kicked out of RAID after the kernel reads from that block.
Such a setup would likely cause significant performance degredation due to excessive head seeking during all disk IO.
Is the threat of writing random data during power loss a real one? Are there other solutions to this problem?
EDIT: I should have been more clear. I believe the idea of putting a RAID1 on
a single disk is a very bad idea. I'm asking about this because I heard of
someone who thought it was a good idea and has implemented more than one
system like this. I was hoping to put this idea to rest once and for all.
I was trying to figure out what possible reason they would have for this
design, but I was later told that this was likely the result of a naive
response to unplanned growth during a very hectic time.
I tried thinking of a situation where this might be useful, such as the idea
of a payload for a linux filesystem modification getting corrupted, with the
command to send the data remaining uncorrupted. I recognize that's unlikely,
so it seems that this issue can be put to rest after all. Thank you @gene! : )
Comment: Too theoretical. Are you trying to describe a real situation?
Comment: This just expands the window in which we're vulnerable to a failure. Consider two writes where we're screwed if one is completed by not the other. With the extra seeks required, the window between when the first one finishes and when the second one starts will be longer. So we're worse off.
Answer:
Is the threat of writing random data during power loss a real one?

For power loss:  Random?  Unlikely.  Corrupted (half written data, etc)?  Sure.
For a power surge:  I guess there might be a possibility that random data might be written, but if the surge has reached far enough into the system to affect memory it's more likely you'll be worried about putting out an electrical fire and total data loss than a few bits of random data.

My guess is that... random data cannot be written to each RAID member simultaneously

RAID1 will attempt to write the data simultaneously, but being as your scenario has the volume on a single spindle perhaps this would happen.  Huge if, I doubt anyone has tried this.  And you face the possibility that corrupt data will be written to one side of the volume and nothing (or a smaller amount of corrupt data) being written to the other side.

Are there other solutions to this problem?

Use more than one physical drive in the RAID volume. :)
Resilvering/Scrubbing RAID volumes will typically find errors and attempt to fix, discard, or quarantine them.
Journaling file systems will help as well.
As @womble mentioned in the comments, file systems that have built-in checksum support would also help with identifying corrupt data.
You can also do things like provide adequate surge protection, have the server on an uninterruptible power supply, and use a hardware RAID controller with a built-in battery and cache (which would allow the controller to finish writing out the cached data when the storage becomes available again).
Comment: Checksum/FEC-using filesystems would be even better, from an error detection/recovery perspective.
Comment: Excellent point, @womble.  I'll add that above.


Dropdowns with subtitle and buttons on the right side

Question: I have two dropdown items next to each other in a container (select-container). I want to have a subtitle (sub-container) below this container. Next to the container more buttons should appear. If the screen size is to large the buttons should float to the next line - but stay on the right side.
I tried to create a wrapper (div) around everything, set display:flex and the buttons wrapped in a container with display:inline-flex but didn't succeed very much. I tried as well the button-container with
{
    display: inline-flex;
    flex-direction: row;
    justify-content: flex-end;
    align-items: center;
}

but didn't succeed since the subtitle start floating around.
Any hint how to structure the HTML (and CSS) properly? Just a side note: normally the space on the right is sufficient but sometimes it to less ==> I want to have them wrapped on the right side only.
Answer: This might help you:

.wrapper {
  display: flex;
  justify-content: space-between;
}

.col {
  display: flex;
  flex-direction: column;
}

      <select name="opt1">
        <option>Value 1</option>
        <option>Value 2</option>
        <option>Value 3</option>
        <option>Value 4</option>
      </select>
      <select name="opt2">
        <option>Value 1</option>
        <option>Value 2</option>
        <option>Value 3</option>
        <option>Value 4</option>
      </select>

Lorem, ipsum dolor sit amet consectetur adipisicing elit. Beatae, iusto?

    <button>Button 1</button>
    <button>Button 2</button>

Codepen: https://codepen.io/manaskhandelwal1/pen/QWGjgWK
Comment: Thx - this is close to what I'm looking for. Is there a way to let `Button1` and `Button2` stay next to each other (=same line). If there is not enough space they should wrap. If the space after wrapping is again to small ==> start wrapping `options`. With the current config the `options` are wrapped first (which isn't the way I'm looking for).
Comment: @LeO you can use `media queries` to achieve it.
Comment: Hmmm... well - since this depends on the length of the text and the options its hard to know in advance. I thought perhaps with `flex-grow` or `flex-shrink` it could work. But didn't succeed.