Running papermill I get a FileNotFound Error

Question: I'm running papermill 2.1.0  in a newly created virtual environment in Mac OS
When I execute a simple notebook I get: FileNotFoundError, referring to and old file that no longer exists.
papermill 59848931.ipynb 59848931-out.ipynb

I get the following:
Input Notebook:  59848931.ipynb
Output Notebook: 59848931-out.ipynb
Executing:   0%|                                                                                | 0/2 [00:00<?, ?cell/s]Failed to run command:
['/Users/user/Documents/Development/python/virtual_environments/udemy_tensorflow_venv/bin/python3', '-m', 'ipykernel_launcher', '-f', '/var/folders/p2/jh8vcbv51ks2gzvfx3dw1bd000_wjb/T/tmp3cf56dkh.json', '--HistoryManager.hist_file=:memory:']
    PATH='/Users/user/Documents/notebooks/venv/bin:/Users/user/google-cloud-sdk/bin:/Users/user/Downloads/google-cloud-sdk/bin:/anaconda3/bin:/anaconda/bin:/Users/user/homebrew/bin:/Users/user/bin:/Library/Frameworks/R.framework/Versions/Current/Resources/:/usr/local/git/current/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/go/bin:/usr/local/share/dotnet:/opt/X11/bin:~/.dotnet/tools:/Applications/Wireshark.app/Contents/MacOS:/Users/user/Documents/Development'
    with kwargs:
{'stdin': -1, 'stdout': None, 'stderr': None, 'cwd': None, 'start_new_session': True}

Executing:   0%|                                                                                | 0/2 [00:01<?, ?cell/s]
Traceback (most recent call last):
  File "/Users/user/Documents/notebooks/venv/bin/papermill", line 10, in <module>
    sys.exit(papermill())
  File "/Users/user/Documents/notebooks/venv/lib/python3.6/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/Users/user/Documents/notebooks/venv/lib/python3.6/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/Users/user/Documents/notebooks/venv/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/user/Documents/notebooks/venv/lib/python3.6/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/Users/user/Documents/notebooks/venv/lib/python3.6/site-packages/papermill/cli.py", line 235, in papermill
    execution_timeout=execution_timeout,
  File "/Users/user/Documents/notebooks/venv/lib/python3.6/site-packages/papermill/execute.py", line 104, in execute_notebook
    **engine_kwargs
  File "/Users/user/Documents/notebooks/venv/lib/python3.6/site-packages/papermill/engines.py", line 49, in execute_notebook_with_engine
    return self.get_engine(engine_name).execute_notebook(nb, kernel_name, **kwargs)
  File "/Users/user/Documents/notebooks/venv/lib/python3.6/site-packages/papermill/engines.py", line 343, in execute_notebook
    cls.execute_managed_notebook(nb_man, kernel_name, log_output=log_output, **kwargs)
  File "/Users/user/Documents/notebooks/venv/lib/python3.6/site-packages/papermill/engines.py", line 402, in execute_managed_notebook
    return PapermillNotebookClient(nb_man, **final_kwargs).execute()
  File "/Users/user/Documents/notebooks/venv/lib/python3.6/site-packages/papermill/clientwrap.py", line 36, in execute
    with self.setup_kernel(**kwargs):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/contextlib.py", line 81, in __enter__
    return next(self.gen)
  File "/Users/user/Documents/notebooks/venv/lib/python3.6/site-packages/nbclient/client.py", line 404, in setup_kernel
    self.start_new_kernel_client(**kwargs)
  File "/Users/user/Documents/notebooks/venv/lib/python3.6/site-packages/nbclient/util.py", line 37, in wrapped
    result = loop.run_until_complete(coro(self, *args, **kwargs))
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 467, in run_until_complete
    return future.result()
  File "/Users/user/Documents/notebooks/venv/lib/python3.6/site-packages/nbclient/client.py", line 375, in async_start_new_kernel_client
    await ensure_async(self.km.start_kernel(extra_arguments=self.extra_arguments, **kwargs))
  File "/Users/user/Documents/notebooks/venv/lib/python3.6/site-packages/nbclient/util.py", line 57, in ensure_async
    result = await obj
  File "/Users/user/Documents/notebooks/venv/lib/python3.6/site-packages/jupyter_client/manager.py", line 542, in start_kernel
    self.kernel = await self._launch_kernel(kernel_cmd, **kw)
  File "/Users/user/Documents/notebooks/venv/lib/python3.6/site-packages/jupyter_client/manager.py", line 523, in _launch_kernel
    res = launch_kernel(kernel_cmd, **kw)
  File "/Users/user/Documents/notebooks/venv/lib/python3.6/site-packages/jupyter_client/launcher.py", line 135, in launch_kernel
    proc = Popen(cmd, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 1344, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/Users/user/Documents/Development/python/virtual_environments/udemy_tensorflow_venv/bin/python3': '/Users/user/Documents/Development/python/virtual_environments/udemy_tensorflow_venv/bin/python3'

I reinstall Python3, papermill and virtualenv and same issue
Answer: I reinstalled my IPython kernel
python3 -m pip install ipykernel
python3 -m ipykernel install --user


For any of the $16$ subsets with cardinality $3$ of $\mathbb Z_7$, show there always exists $2$ sets s.t. the sum of elements are equal.

Question: Problem: For any of the $16$ subsets with cardinality $3$ of $\mathbb Z_7$, show that there always exists two sets, so that if you sum the elements of one set, it is the same as the other. For instance, $\sum ${$1,2,3$}=$\sum ${$5,1,0$}.
My solution: I first set bounds on $\sum X$, where $X$ is a subset of $\mathbb Z_7$. Well, we know that the minimal sum is $0+1+2=3$, so $3\leq \sum X$. And we also know that the maximum value of this sum is $4+5+6=15$, so we have the bounds $3\leq \sum X \leq 15$. Thus $\sum X$ can take at most $12$ different values. Let $A$ be the set of all possible values of the $12$ digit sums of $X$. Similarly, denote $B$ as the set of all possible values of the $12$ digit sums of $Y$. We then have that the problem reduces to the following statement: $A \cap B \neq 0$.
Assume that $A \cap B =0$. Then if we denote $C$ as the set of all possible sums of all possible subsets of $\mathbb Z_7$, we have that $|C|=12$. Also note that by the inclusion-exclusion principle, $|A \cup B|$=$|A|+|B| -$$|A \cap B|$=$24$. But then notice that $|A \cup B|$=$|C|$=$12$. A contradiction.
After this, one can make the more general statement that this could work for any two sets, for any value of the sums of those sets, and be far more general.
I would like to know whether my solution is correct and that if one could try and apply the pigeonhole principle to this problem.
Comment: "*First, I set bounds on $\sum X$*"  Uh... Minimum value of $3$?  But $1+2+4=0$ in this context I thought?  There are just seven possible sums, $0,1,2,\dots,6$.  We could have gotten away with there being just eight such sets.
Comment: OOPS! I was lazy, and wanted to just use $\mathbb Z_7$ instead of {$0,1,2,3,4,5,6$}! My bad!
Comment: You can use $[7]$ to represent $\{0,1,2,3,\dots,6\}$ instead.  Note that some authors prefer this to be $\{1,2,3,\dots,7\}$ so you do have to occasionally clarify if it matters.  Most times though it doesn't matter at all as it is just meant to be "the quintessential set with seven elements" and the results being talked about are the same regardless which was intended.  For example the number of functions from $[n]$ to $[m]$ is $m^n$
Comment: So then, we have some number of three-element subsets of $[7]$ and are wanting to show that at least two of these have the same sum, whatever that might be.  You correctly found then that $0+1+2=3$ is smallest and $4+5+6=15$ is largest, giving a range of $13$ possible sums (*don't forget the first and last in your count*).  We have more than $13$ subsets to look at and compare, so we are done by the pigeonhole principle by letting the sets be the pigeons and the possible sums be the holes.  No additional explanation needed.
Comment: There are $13$ different integer values $S$, not just $12$, satisfying $3 \leq S \leq 15$. And where did $Y$ come from?
Comment: Thank you! So $ceil(16/13)=2$, where $16$ is the number of sets, and $13$ is the number of possible sums. Correct?
Comment: $Y$ is a set like $X$. A set so that $|X|$=$|Y|$=$3$
Comment: Where does 16 come from?  $\binom{7}{3}=35$.
Comment: @RobPratt The question was poorly worded, yes.  My interpretation is "*Supposing we were given $16$ arbitrary subsets of size three of $\{0,1,2,\dots,6\}$, show that...*"  That there are more unused subsets is irrelevant.
Answer: For any $3$-element subset of the set $\{0,1,2,3,4,5,6\}$, you correctly note that its sum is at least $0+1+2=3$ and at most $4+5+6=15$. This leaves at most $13$ possible values for the sum of such a $3$-element subset. Hence $16$ such subsets cannot all have distinct sums, meaning that there are at least $2$ subsets with the same sum.


How can i use bootstrap js library in my theme?

Question: I use bootstrap drupal theme. And i want to use collapse.
I added in theme.info the library path bootstrap.js have cleaned the cache, but after using the following code generates only the button, but the content is not deployed.
<code>      <a class="btn btn-primary" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
</code>

Most likely is not initializing bootsrap.js, please tell me how to fix it?
Comment: I just ran this [example](http://getbootstrap.com/javascript#collapse-example) with no problem inside a body text field. I have [bootstrap](https://www.drupal.org/project/bootstrap) installed, loading bootstrap files from CDN, and did not have to add bootstrap.js at all. Inspect your browser console for errors.
Answer: Yes i fixed this problem by using jQuery with more higher version.


Orthogonality of associated Legendre polynomials

Question: Let $P_n(x)$ be the $n$-th degree Legendre polynomial. Let $k$ be a nonnegative integer less than or equal to both $n,m$. How to prove that
$$ \int_{-1}^1 (1-x^2)^k D^kP_n(x) D^kP_m(x)\,dx = \frac{2(n+k)!}{(n-k)!(2n+1)}\delta_{mn}, $$
where $D^k$ stands for derivative of order $k$, and $\delta_{mn}$ stands for Kronecker delta.
I think somehow we will use the orthogonality of $P_n, P_m$ and the norm of $P_n$, but I don't see how.
Comment: One way is to  introduce $f_{n,k}(x) = (1-x^2)^{k/2} D^kP_n(x)$, and to prove by induction on $k$ that $f_{n,k}$ satisfy a certain [2nd order ODE](http://en.wikipedia.org/wiki/Classical_orthogonal_polynomials#Associated_Legendre_polynomials). This makes them eigenfunctions of a differential operator for different eigenvalues, hence orthogonal.
Answer: Let $I(k,n,m)$ be the considered integral.
(1) Since $\deg P_n=n$, we see immediately that $I(k,n,m)=0$ if $k>n$ or $k>m$.
(2) Since $I(k,n,m)=I(k,m,n)$, we see that the remaining case to be considered is
$0\leq m\leq n$.
(3) Assume that $0\leq m\leq n$. Noting that $-1$ and $1$ are multiple zeros of $(x^2-1)^kD^kP_m$ of multiplicity $k$, we obtain by using k-successive integrations by parts
$$
I(k,n,m)=\int_{-1}^1P_n(x)D^k\left((x^2-1)^kD^{k}P_m(x)\right)dx
$$

The polynomial $Q(x)=D^k\left((x^2-1)^kD^{k}P_m(x)\right)$ has degree $m$. So, if $m<n$ we obtain $I(k,n,m)=0$.
The remaining case is when $m=n$. Here $\deg Q=n$. Recalling that the leading
coefficient of $P_n$ is $a_n=\frac{1}{2^n}\binom{2n}{n}$ we see that $P_n(x)=a_n(x^n+R_{n-1})$ with $\deg R_{n-1}<n$. Thus
$$
\eqalign{
Q(x)&=D^k\left((x^2-1)^kD^{k}P_n(x)\right)\cr
&=a_nD^k\left((x^2-1)^k\frac{n!}{(n-k)!}(x^{n-k}+R_{n-1}^{(k)})\right)\cr
&=a_n\frac{n!}{(n-k)!}D^k\left( x^{n+k}+S(x)\right)\quad\hbox{with $\deg S<n+k$}\cr
&=a_n\frac{n!}{(n-k)!} \frac{(n+k)}{n!}(x^n+T(x))\quad\hbox{with $\deg T<n$}\cr
&=a_n \frac{ (n+k)!}{(n-k)!} x^n+\hbox{terms of degree $<n$}\cr
&=\frac{ (n+k)!}{(n-k)!} P_n+\hbox{terms of degree $<n$}
}
$$
It follows using orthogonality
$$
I(k,n,n)=\frac{ (n+k)!}{(n-k)!} \int_{-1}^1 P_n^2(x)dx=
\frac{ (n+k)!}{(n-k)!}\frac{2}{2n+1}
$$
since $\Vert P_n\Vert^2=\frac{2}{2n+1}$.

As a conclusion, the only cases where $I(k,n,m)$ is different from  $0$ is when
$n=m$ and $0\leq k\leq n$, and in this case
$$
I(k,n,n)=\frac{ (n+k)!}{(n-k)!}\frac{2}{2n+1}.
$$


UIView scrolling vertical when it shouldn't

Question: I'm having some strange behaviour. I have a UIScrollView setup in the interface builder. I have this code:
<code>    //set up scrollview
    UIView *content = [[[NSBundle mainBundle] loadNibNamed:@"SelectStickerView" owner:self options:nil] objectAtIndex:0];
    self.scrollView.contentSize=CGSizeMake(620 ,155);
    [self.scrollView addSubview:content];
</code>
for some reason it is scrolling vertically now, but the content size is set to exactly the same as the content UIView size. It works fine in my other UIViewController but not on this one! Any ideas what could be wrong?
Comment: Are you using Autolayout?
Comment: I don't have any constraints or anything set no
Comment: You don't have to add constraints. Is the checkbox check?
Comment: it's enabled yes, but it's also enabled for my other view controller and it works fine in that.
Comment: Does the other one has the scroll view in the xib or you're adding it as a subview programmatically?
Comment: scrollview in a xib exactly like the one above. it's so strange
Comment: Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/71697/discussion-between-ashraf-tawfeeq-and-kex).
Comment: When the **content size** is the same as the **scroll view size**, it won't scroll. If your content size is bigger than the scroll view size, it will scroll. Scrolling is not dependent on the `scrollView.contentSize` being the same as its contained view's size.
Comment: @IanMacDonald my content size is bigger than the scrollView size. The scrollView size is 155x155 and the content is 620x155
Answer: I figured this out and want to post the answer in case it's useful for someone else. I added:
<code>[self setAutomaticallyAdjustsScrollViewInsets:NO];
</code>
and it fixed the problem. It works fine in my other UIViewController without this line, maybe it's something to do with the auto layout but I guess if you always use this line you can cover your bases. Cheers guys


IRPStackSize and Accessing Windows 7 Shares from Windows XP clients

Question: I received a new Windows 7 workstation (replacing an older Windows 7 workstation) and started running into errors accessing my file shares from Windows XP machines.
I get various errors that seem to come and go (at some points it will work fine for hours). One is:

Not enough storage is available to
  process this command

I also see random failures to open files in applications that try to access lots of files from the share.
Microsoft publishes a cryptic knowledgebase article on the subject that suggests increasing IRPStackSize to fix the problem without any explanation as to why you would need to do so.
I found that increasing the IRPStackSize on both my workstation and the client XP machine seems to make the problems go away.
However, why do I need to do this? Why would one Win7 machine have this problem and another not? They are all on the same domain, so group policy pushes down the same settings to them, some of which I've manually verified. How do I know what the appropriate value is? Or should I just set to to the max of 50?
Answer: This is what tipped me off:
"I also see random failures to open files in applications that try to access lots of files from the share."
Windows uses a layered I/O model, where drivers attach to each other and utilize the services of the underlying driver to perform their work. A layer of drivers that utilize each other's services are typically referred to as a, "driver stack."
You have too many filters in the particular stack (The number of requests each going through the layers of Antivirus, base filtering engine, ntfs, etc. etc.) so the default IRPStackSize isn't large enough. Increasing the default allows for all of the filters to have their own I/O stack location and everyone is happy. This is not a general Windows problem, but just a limitation of certain drivers in the system.
Consider hosting your heavily used file shares on a file server, and then read the 2008 R2 Tuning Guide, specifically the part about tuning file server performance: http://msdn.microsoft.com/en-us/windows/hardware/gg463392
Comment: A year later and I still haven't solved this problem, but have mitigated it by getting rid of XP... You've given me an idea though, that the antivirus is probably to blame somehow. Ought to be easy enough to confirm. Moving the files to another server is not an option. This is a personal share. In retrospect, this question may not have belonged on serverfault...
Comment: A blast from the past! Hosting busy file shares on workstations is  asking for trouble anyway. Besides all this talk of IRPStacksize... you've also got the much more straightforward disadvantage that Windows Desktop SKUs artificially limit the number of simultaneous connections made to it. Basically so that you can't use your workstation as a server. :P
Comment: I never was satisfied with any solution to this. I still see it in cases where it is Windows 7 only, or Win7 + Linux. When I said 'lots of files', I just mean some basic file access like running a debugger from a single remote system on a file share...


Exploratory factor analysis on multiple imputation using R

Question: I would like to carry out an exploratory factor analysis on multiply imputed datasets according to the methodology by Nassiri et al.
They have created an R package for this (mifa), but unfortunately, there doesn't seem an option to dictate which variables should be used as predictors for multiple imputations and which should be used for the EFA (they are not the same in my case).
I would still like to apply their methodology manually. They first estimate the covariance matrix from the imputed sets of data using Rubin's rules, and then apply the EFA on this combined covariance matrix.
My question is: is it ok to use the correlation matrix instead of the covariance matrix? Much of the EFA reading I've come across factor analyses the correlation matrix and it's what I've used for my complete-case analysis. I wonder if there are any cases when the covariances matrix should be used, and why?
Comment: This may help https://stats.stackexchange.com/questions/53/pca-on-correlation-or-covariance
Comment: @AleksejsFomins Thank you! This answered my question. My variables are already z-transformed so I will use the covariance matrix. I can't seem to be able to upvote your answer :'(
Comment: Ok, I'll make an answer for you, so you can upvote :)
Answer: Dimensionality reduction techniques (such as PCA and FA) can be computed via covariance or correlation matrices, where the latter is equivalent to z-scoring the data by each dimension prior to the calculation. The major difference between the approaches is that results for raw data (covariance) are influenced by combination of individual variance and covariance, whereas results for z-scored data (correlation) are explicitly independent of individual variability
See here for more discussion


How to add section header/footer view when using AsyncDisplayKit?

Question: It seems that currently ASTableNode and ASTableView both lack the support of section header/footer view.
I cannot only find a protocol method:
- (nullable NSString *)tableNode:(ASTableNode *)tableNode titleForHeaderInSection:(NSInteger)section

which shows nothing.
And the delegate/dataSource setter methods have been intercepted by AsyncDisplayKit, so that I cannot use the UIKit's way to do it.
So can I add section header/footer view when I'm using AsyncDisplayKit?
Answer: Just find out that ASTableNode will call the UITableViewDelegate methods.
So just implement the methods
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;

And it will work just like before.
Comment: Except this requires you to use UIKit (UIView) and not AsyncDisplayKit


.htaccess doesn't work on xampp (windows 7)

Question: I'm setting my .htaccess file right now to use friendly urls (manually). But, when i go to the url the server shows me Error 404.
RewriteEngine on

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

Rewriterule ^register$ register.php

I'm really sure that mod_rewrite is enabled because i see it when use phpinfo().
Answer: Even though mod-rewrite is enabled, by default it is not enabled for .htaccess files.
Hold Your Breath

Open xampp control panel
Stop Apache
Click the Config button on the Apache row, and select httpd.conf
In that file, search for something like xampp/htdocs">
A bit lower, you may see a line like this: # AllowOverride All. Remove the #, which is a comment
Alternately, search for AllowOverride All, make sure it is in the right section, and remove the comment #
Save the file
Restart Apache, say a prayer, cross  your fingers and hold your breath
Comment: Glad to hear it. It must have been the prayer. :) :) Thanks, see you next time!
Answer: This listing may be old but is still relevant so to make it a little more secure it is probably best to add a few lines.
Deny from all
Allow from 127.0.0.1 ::1 localhost
Allow from .htaccess

Also as a side note .htaccess files slow the speed of the server so it would be best to refer to xampp documentation for best practices.
Hope it helps.
Answer:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

if we want to remove index.php form url .First we create a .htaccess file on root directory of project with out any extension. And add this code in this file and so remove the index.php  Application/config/config.php
Comment: Thank you for this code snippet, which might provide some immediate help. A [proper explanation would greatly improve its long-term value](https://meta.stackexchange.com/q/114762/206345) by showing _why_ this is a good solution to the problem, and would make it more useful to future readers with other, similar questions. Please [edit] your answer to add some explanation, including the assumptions you've made.
Answer: Check in httpd.conf you  tag, review this property
AllowOverride All

AllowOverride authorize use htaccess file.


how to get the url to usefor a private path

Question: if I have a file saved in private:://somefile.txt  , what function can I use in drupal to give me the external URL to access that?
I tried PrivateStream::getExternalUrl()
but I get this error
PHP Fatal error:  Call to undefined method Drupal\mymodule\myservice::getTarget() in /opt/DrupalSites/drupal-wcms-migration/docroot/core/lib/Drupal/Core/StreamWrapper/PrivateStream.php on line 50
Answer: You can't call PrivateStream::getExternalUrl() directly because it's not a static function; it needs an instantiated stream before you can call getExternalUrl() on it.
You can retrieve it via the stream wrapper manager's getViaUri() method:
$stream = \Drupal::service('stream_wrapper_manager')->getViaUri('private:://somefile.txt');
$stream->getExternalUrl();

Answer: You don't have to call getExternalUrl() directly either, you should just use file_create_url('private://somefile.txt').
There is no OOP version of it yet, this is being worked on.


Closures and complements in Hilbert spaces

Question: Let $H$ be a Hilbert space, and $V \subseteq H$ a linear subspace. Denoting $$
V^{\perp} := \{w \in H; \text{such that }  \langle w,v\rangle = 0, \text{ for all } v \in V\}.
$$
Is it clear that $V^{\perp}$ is a closed set? If it is, then is it true that
$$
(V^{\perp})^{\perp} = \overline{V},
$$
where $\overline{V}$ denotes the closure of $V$?
Answer: The orthogonal complement is closed, and as far as if this is clear, it depends on your definition on clear- it is not hard to prove.
Here's a simple proof: let $(x_j)$ be a sequence in $V^\perp$ converging to $x\in H$. By definition, $\langle x_j, y\rangle=0$ for all $y\in V,$ for each $j$. Using the continuity of the inner product, we conclude by taking the limit that $\langle x,y\rangle =0$, and so $x\in V^\perp.$
Also, as you conjectured in your post, it is true that $(V^\perp)^\perp=\overline{V}.$ Indeed, $V^\perp=\overline{V}^\perp,$ and so $\left(V^\perp\right)^\perp=\left(\overline{V}^\perp\right)^\perp=\overline{V},$ where we have used that $\left(C^\perp\right)^\perp=C$ when $C$ is a closed set.


Qual é o objetivo dessa linguagem chamada Brainfuck?

Question: Existe uma linguagem de programação chamada Brainfuck que tem uma sintaxe bem confusa e de difícil compreensão.
Por exemplo, para se fazer um simples Hello World na mesma, você tem que fazer o seguinte:
++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.

Vendo essa pequena "string", podemos perceber o porquê do nome da linguagem.
Então, levando em consideração a difícil sintaxe da linguagem (e o nome), gostaria de saber qual é o objetivo da existência da mesma?
Isso é  uma brincadeira que fizeram ou essa linguagem realmente pode ser usada para construção de aplicações?
Mais um exemplo:
Comment: O objetivo já é descrito pelo nome da linguagem.
Answer: Essa linguagem faz parte de um conjunto de linguagens que tem mais aplicações teóricas que práticas. Da Wikipédia (tradução livre):

Apesar de ser equivalente à máquina de Turing, [a linguagem] não foi desenvolvida para aplicações práticas, mas apenas para desafiar e entreter os programadores.

É um tipo de brincadeira, mas como ela é Turing complete, pode ser usado para criar qualquer aplicação (não que alguém vá fazer isso na prática). Você vai achar vários exemplos de sua utilização no Programming Puzzles & Code Golf.
Comment: **Brainfuck** é a segunda linguagem de programação mais fodástica que existe no contexto de ser *Turing complete*. A mais foda de todas é outra que surgiu a partir dela, a **Boolfuck**.


Inter DC traffic from L2 to L3

Question: I'm doing a graduate degree in Data- and Telecommunication  and as part of my last year I'm doing a project within a company.
My company wants me to redesign their inter-datacenter connections, moving them from layer 2 to layer 3 and putting them all in 1 vlan.
Their reasoning for doing this is to make it more manageable, but I'm looking for a more theoretical approach to this.
The question / dl;dr
Why is L3 better than L2 for traffic between data centers?
Comment: It does seem a little in conflict to say you want to eliminate a layer 2 connection, but then put everything in one VLAN, by nature if you're separate by a layer 3 link you will have different subnets and in turn different VLANs on each side.
Answer: Layer 3 datacenter interconnects FORCE you to make certain compromises. A given subnet can only exist either on one side or the other. When the datacenter interconnect fails, you can fail an entire network over, or not. Now, L2 is simple, but can cause some serious issues when it comes to performance and troubleshooting as you've basically one or more shared broadcast domains between sites.
So in essence, to give you a short answer: Layer 3 DCI's force you to make design compromises that in the long term will probably result in performance and reliability gains, but these architecture decisions can and probably will lead you to having to do more engineering and architecture.
Each of these decisions need to come for a reason and unless you're having a PROBLEM, I would say why change something that's not broken? You need to define your objectives and reasons for them before engineering a best fit for your organization. A small company with relatively few business dependent DR needs can probably use a L2 connection and some trunked VLANs for some nice simplicity. Someone building a multi-server farm of databases or application servers made available to the Internet and in turn used to RUN the business will have higher requirements.
Comment: I recommend Ivan Pepelnjak's blog for further reading on these subjects: http://blog.ioshints.info/2011/12/large-scale-l2-dci-true-story.html

Inter DC traffic from L2 to L3


$f(x_1,y_1)=f(x_2,y_2)\iff x_1=x_2\quad,\quad y_1=y_2$

Question: I came upon a question and I'm stuck on solving it.

Does there exist any continuous function $f:\Bbb R^2\to \Bbb R$ such that $$f(x_1,y_1)=f(x_2,y_2)\iff x_1=x_2\quad,\quad y_1=y_2$$?
What if we drop the continuity constraint? (though, the function is better be well-defined)

Originally, this question comes from a physical background. If two inertial frames measure the 4-tuples $(\Delta x,\Delta y,\Delta z,\Delta t)$ and $(\Delta x',\Delta y',\Delta z',\Delta t')$, we have $$\begin{cases}\Delta x^2+\Delta y^2+\Delta z^2-c^2\Delta t^2=\Delta x'^2+\Delta y'^2+\Delta z'^2-c^2\Delta t'^2
&,\quad\text{Special Relativity}\\
\Delta x^2+\Delta y^2+\Delta z^2=\Delta x'^2+\Delta y'^2+\Delta z'^2\\\text{and}
\\\Delta t=\Delta t'
&,\quad\text{Classical Physics}
\end{cases}$$
I am OK with special relativity, but about the the second equivalence, I wonder if a function $f$ is found such that $$f(\Delta x^2+\Delta y^2+\Delta z^2,c^2\Delta t^2)=f(\Delta x'^2+\Delta y'^2+\Delta z'^2,c^2\Delta t'^2)\\\iff \\
\Delta x^2+\Delta y^2+\Delta z^2=\Delta x'^2+\Delta y'^2+\Delta z'^2\\\text{and}
\\\Delta t=\Delta t'
$$
Comment: You are asking if there is a one-to-one function $\mathbb{R}^2 \to \mathbb{R}$.
Comment: Yes. Another way of saying that.
Comment: see: https://math.stackexchange.com/questions/197735/injective-function-from-mathbbr2-to-mathbbr
Comment: Oh. Thanks for that!
Comment: Also https://math.stackexchange.com/questions/75107/injective-map-from-mathbbr2-to-mathbbr
Answer: For $f$ continuous, let $f(a,b)>f(c,d)>f(e,g)$.
Choose any path from $(a,b)$ to $(e,g)$ avoiding $(c,d)$. The image of this path is a path which must include all points between $f(a,b)$ to $f(e,g)$.
Thus there is another point with the same image as $(c,d)$.

A neat (?) function $f$ if the continuity constraint is dropped.

For $x\in \Bbb R$ define $a(x)=\frac{e^x}{2e^x+1}$.
For $x\in \Bbb Q$ define $b(x)=0.5+\frac{x}{\sqrt 5}$. For $x\in \Bbb R- \Bbb Q$ define $b(x)=x$.
Using the continued fraction form for irrational numbers in $(0,1)$, define $c([0;x_1,x_2,...],[0;y_1,y_2,...])=[0;x_1,y_1,x_2,y_2,...]$.
We can then define the function $f$ from $\Bbb R^2\to \Bbb R$ by
$$f(x,y)=c(ba(x),ba(y)).$$
Comment: Note:  this makes use of continuity. If we drop continuity, it is possible.
Comment: Yes, is there a function with a neat/elementary definition?
Comment: Not that I'm aware of.
Comment: @Randall I've made a stab at something which looks reasonably neat.


Evaluate Path Integral

Question: Consider the vector field
F=\begin{pmatrix}
       -3z^2sinx            \\[0.3em]
       8y^3z \\[0.3em]
       2y^4+6zcosx
     \end{pmatrix}
By evaluating the path integral, compute
$\int\limits_C F.t $ ds where the path C is a straight line that begins at $(3\pi/2,2,-1)$ and ends at the point $(X,Y,Z)$ where $X,Y,Z$ are fixed values.
Now Ive had a go, parametrised the curve to get
$x=3\pi/2(1-t)+Xt$,
$y=2(1-t)+Yt$
$z=-1(1-t)+Zt$
I was wondering where I go from here, simply evaluating $F(x(t),y(t),z(t))$, at least the way I have approached it seems like a lot of work with what I have (plugging in x,y and z) .
So I guess I am asking: Am I correct thus far and what is the best way to continue?
Answer: What you have done is correct, but a simple way of doing this
For a scalar field $$S=2y^4z+3z^2cosx$$
F is gradient of S i.e., $F=\bigtriangledown S$
Hence $\int Fdt=\int\bigtriangledown S=S(X,Y,Z)-S(\frac{3\pi}{2}, -2,1)=S(X,Y,Z)-32$

Evaluate Path Integral


Dissonance from the decay of fast notes is called what?

Question: If an instrument with slow decay plays a fast melody, dissonance from the last note and the decay of the previous note can easily produce dissonance.
Is there a technical term for this specific kind of dissonance?
Comment: I'll be delighted to be wrong, but I don't think there is a specific term for dissonance where some of the contributory notes are in their decay phase. Excellent question though!
Comment: Do you mean sustain of the first note?  When you say that the decay is "slow" I tend to think of it as sustaining too long.  Whereas "decay" leads me to think there won't be any harmony between the first and last note.  I would be interested to see what answers emerge.  I would guess dissonance is dissonance and this is just one of many ways to create it with harmony.  By the way, if an instrument decays slowly and note are not meant to be sustained then I would think the player should mute the older notes.  Can you give and example of an instrument?
Comment: This is easily reproduced on the piano by holding down the damper pedal. The technical term for this effect is, I believe, "muddy". :-)
Comment: For example guitar where older notes are not muted.
Comment: If you meant to sustain the notes then you are basically creating harmony and I would think that it's just one example of dissonant harmony.  If, on the other hand, the note was not supposed to be sustained then the piece is being played incorrectly or with poor technique.
Comment: Are you referring to the concept used in synthesizers where they commonly have and ADSR Envelope (Attack, Decay, Sustain, and Release)? These are all adjustable parameters and define how the notes are executed over a period of time.
Comment: I am referring to the decay/release of a note still being audible when next note is played, which can produce dissonance. What I would like to know is the name for that type of dissonance (if it has a name).
Answer: Although I don't think there's a widely-accepted term for the specific phenomenon you're describing, it has some analogy to appoggiatura, which is sometimes done with a tone in the melody from the previous beat that is "held over" for a moment in the following beat after the chord changes. The analogy isn't perfect, because an appoggiatura is actively resolved to a consonant tone, whereas in the situation you're describing the sound simply decays away. The effect is somewhat similar, though, because it results in a "dissonant attack" that quickly leads to consonance as the dissonant element dissipates, and if the appoggiatura is done with the note from the previous beat it also has something of an "echo-y" character.
If you want to refer to this phenomenon concisely, I think a lot of people would understand you if you used a phrase like "clashing decay" or similar, although you might have to explain yourself initially. My guess as to why there's not a widely-used jargon term is because an instrument with long decay decays everything homogeneously, so unless the decay is very long, you tend to hear it as a kind of echo or reverb (i.e. part of the texture) as opposed to having a functional role in the harmony. When I'm frustrated with this characteristic in an electronic instrument, i.e. when trying to work with fast lines as you describe, I usually call it "smearing", but more because the notes tend to run together than that they form dissonances.
As a side note, if you're interested in this phenomenon, I encourage you try composing music with one or more of the voices delayed by some ratio of the beat, so that the harmony and counterpoint gestures you normally turn to come out "phased" or what have you. You can find very nice things this way.


How to integrate Gravitational force?

Question: The gravitational force is given by
$$
F = \dfrac{-Gm_1m_2}{r^2}
$$
But, since F = ma, then for an object placed at r distance away from the centre of the earth it would experience
$$
a = \dfrac{-Gm}{r^2}
$$
where m is the mass of the earth. So if I wanted to find the relationship between the position and time of the object, I'd have to integrate acceleration once with respect to time for velocity, and again for the position. So I try to integrate:
$$
V = -Gm\int \dfrac{1}{r^2} dt
$$
but since r itself is a function of time (which is what I want in the end), i'm not too sure how to integrate it?
HANG ON I THINK I GOT IT
$$
F = \dfrac{-Gm_1m_2}{r^2}
$$
$$
a = \dfrac{-Gm}{r^2}
$$
$$
V = -Gm\int \dfrac{1}{r^2} dt
$$
$$
V^2 = -Gm\int \dfrac{1}{r^2} dt \dfrac{dr}{dt}
$$
$$
V^2 = -Gm\int \dfrac{1}{r^2} dr
$$
$$
V^2 = -Gm (-\dfrac{1}{r} + c)
$$
assuming we are dropping a mass from a distance of s from the earths centre
$$
0 = -Gm (-\dfrac{1}{s} + c)
$$
$$
c = 1/s
$$
$$
V^2 = Gm(1/r-1/s)
$$
$$
V = \pm \sqrt{Gm(1/r-1/s)}
$$
assuming we are dropping a mass from a large r, and it is falling to earth, v is always negative
$$
V = \sqrt{Gm(1/r-1/s)}
$$
$$
\dfrac{dr}{dt} = \sqrt{Gm(1/r-1/s)}
$$
$$
\dfrac{dt}{dr} = \dfrac{1}{\sqrt{Gm(1/r-1/s)}}
$$
$$
t = \int \dfrac{1}{\sqrt{Gm(1/r-1/s)}} dr
$$
$$
t = \dfrac{1}{\sqrt{Gm}} \int \dfrac{1}{\sqrt{1/r + 1/s}}dr
$$
From here i think its just slogging it out
Comment: Line 4 is incorrect. You have to multiply line 2 by $dr/dt=v$ and *then* integrate.
Comment: http://en.wikipedia.org/wiki/Classical_central-force_problem
Comment: It should be 1 over $r^2$
Comment: Typically it would be easier to integrate the force with respect to position to obtain the work integral and work out what you want from there.
Comment: If I do that I can find out the Gravitational Potential Energy at a particular point in space, but I'm trying to relate position to time, so I'm not sure if that helps
Answer: Hint: Multiply both sides of your equation by $v=dr/dt$ and then integrate.
Comment: Integrate again by separating variables. Oh, and don't forget your constants of integration. :)
Comment: Tried that, but I end up with an equation relating Velocity and displacement, and I end up with the same problem?

v = -root(GM/r)

How to integrate Gravitational force?


Segmentation Fault with a pointer to an object holding an unordered_set

Question: #include <unordered_set>

class C {
public:
    std::unordered_set<int> us;
};

int main() {
    C* c;
    c->us.insert(2); // Segmentation Fault
}

What am I doing wrong?
Comment: menory is not allocaed for `c` object
Comment: wow. That was silly of me. Haven't used C++ in a while, can you tell? =P
Answer: You get a segmentation fault because the pointer has not been assigned:
C* c = new C; // <<== Add this
c->us.insert(2);
delete c;    // <<== Free the memory

Unlike objects declared as objects, not as pointers (e.g. C c;) pointers need to be initialized: you should either assign them an address of an existing object, or allocate memory for a new object using the operator new. Dereferencing uninitialized pointers is considered undefined behavior, often causing segmentation faults.
Comment: Or even better, don't make a "new" C at all, cuz you don't need to. Just do `C c; c.us.insert(2);`
Comment: The code in the question is not the actual code that I'm writing. It was the simplest form of my problem that still generated a segmentation fault. In my actual code `c` (which is not actually named "c")needs to be a pointer.


"SceneKit: error, missing buffer [-1/2]" when trying to pass uniforms to a metal shader

Question: I've attached a SCNProgram to a SceneKit's geometry, and I'm trying to pass uniforms to the fragment shader. In my simple code snippet I just pass the output color to the fragment shader as a uniform, which returns it as an output value.
I've already tested the shaders and they work, in the sense that I can succesfully rotate an object in the vertex shader, or draw an object in a different color in the fragment shader, etc... but the problem is when I pass the uniforms. This is my fragment shader:
struct Uniforms
{
    float4 color;
};

fragment float4 myFragment(MyVertexOutput in [[ stage_in ]],
                           constant Uniforms& uniforms [[buffer(2)]])
{
    return uniforms.color;
}

And this is how I try to pass the uniforms in my SceneKit+Swift code:
SCNTransaction.begin()
cube.geometry?.setValue(NSValue(SCNVector4:SCNVector4(0.0,1.0,0.0,1.0)), forKey: "uniforms.color")
SCNTransaction.commit()

But my object (it's a cube) is not even drawn (it's black), and I get this error:

2016-04-01 01:00:34.485 Shaded Cube[30266:12687154] SceneKit: error, missing buffer [-1/0]

EDIT
I tried to follow @lock's suggestions, but I'm still getting the same error. This is the full project repository: https://github.com/ramy89/Shaded-Cube.git
Comment: Hi Ramy could I email you about a potential project? Couldn't find your email address on the GitHub page. Thanks!
Answer: Your shader code looks fine, and the way you're passing the uniform in is close to working.
The name of the shader uniform must match that which is used in setValue. In this case your Metal variable name is uniforms and the value you use in setValue is uniforms.color. These don't match, hence the error you see. Suggest changing the swift code to simply use uniforms in the setValue call.
Next you need to ensure the data passed in as the value to setValue is the same in both Metal and Swift. A SCNVector4 is a struct of four 64bit doubles (CGFloats), whereas Metal's float4 is a struct of four 32bit floats. The documentation seems to indicate you can pass in a SCNVector as a NSValue but I've never got it to work.
In your swift code I'd create a struct to contain the uniforms you want to pass in. There's not a lot of documentation on the vector_float4 struct, but it matches the Metal float4 struct in that it is four 32bit floats.
struct Uniforms {
    var color:vector_float4
}

Pass this into the setValue function as NSData.
let myColor = vector_float4(0,1,0,1)
var myUniforms = Uniforms(color:myColor)
var myData = NSData(bytes:&myUniforms, length:sizeof(Uniforms))
cube.geometry?.setValue(myData, forKey: "uniforms")

I'm not sure you need the SCNTransaction calls, I've not needed them in past and they could be costly performance wise.
update
After looking at Ramy's code it seems there is an issue with setValue and SCNPrograms when applied to the geometry. I can't tell you why, but setting the custom shader to the material seems to fix this, eg;
func makeShaders()
{
    let program = SCNProgram()
    program.vertexFunctionName = "myVertex"
    program.fragmentFunctionName = "myFragment"
    //cube.geometry?.program = program
    cube.geometry?.firstMaterial?.program = program

    var uniforms = Uniforms(color: vector_float4(0.0,1.0,0.0,1.0))
    let uniformsData = NSData(bytes: &uniforms, length: sizeof(Uniforms))
    //cube.geometry?.setValue(uniformsData, forKey: "uniforms")
    cube.geometry?.firstMaterial?.setValue(uniformsData, forKey: "uniforms")
}

Comment: I still get the same error, I don't know what's wrong with my code. I created a github repository and added the link to my question.
Comment: I don't think there is anything wrong with your code @RamyAlZuhouri, see my update above. Looks like a SceneKit bug to me, probably worth filling out a radar.


How can I change a page's title for each page individually?

Question: I am wondering if there is a way that I can change the page titles so that users can see a nice title but that at the same time, the internal title of that same page be different?
Answer: You can use a module that allows you to change it each time or use a different pattern than default Drupal:
Metatag
This module allows you to control a lot more than just the Page title.
Answer: You can modify the title via a preprocess function in .theme file. For example a theme_preprocess_page function


Solving a real jigsaw puzzle with knowledge of the output

Question: I would like to solve a real jigsaw puzzle in Java of dimension n*m by running it through an algorithm. The actual output, i.e., the image is known beforehand. These are my thoughts so far.

Align all puzzle pieces on a piece of paper that is of a color which the puzzle itself does not contain and take a picture.
Crop all pieces to n*m subimages.
Acquire RGB values for every pixel in every piece, disregard the pixels containing the color of the paper (to consider the special shape of every piece).
Get n*m subimages from the actual output image.
This is where I'm having trouble. If I would like to compare the pieces, how do I take the puzzle shape into consideration?

To sum up, is comparing RGB values a promising approach? How would I continue? Are there better, simpler ways like FFT or some sort?
Thank you for your input!
Comment: You have several interesting problems in your question, from image preparation to border-finding to internal representation. Unless you know your way around image processing in java, this is *not* a simple project.
Comment: Do you mean that they all have exactly the same shape ?? (Except on edges and corners.)
Comment: You're right, that's why I like it. However, I'm just not sure what the best way is to "identify" an image. I have heard about Fourier, wavelets etc in college, I just don't know how much of that is really necessary if I have two images that are -almost- the same (differences are probably slight RGB variation and the puzzle shape of course).
Comment: How are the pieces shaped ?
Comment: They are horizontally and vertically aligned like this: http://www.freevector.com/site_media/preview_images/FreeVector-Jigsaw-Puzzle.jpg
Comment: A detailed description of the geometry of the pieces is critical to the selection of a solution.
Comment: I was focusing on the alignment, that is there are only 4 ways to rotate a piece. However, like with most jigsaws, the size may vary: http://previews.123rf.com/images/brunoilfo/brunoilfo1006/brunoilfo100600014/7168030-Background-Vector-Illustration-of-Blank-Jigsaw-Puzzle-each-piece-is-an-editable-blend--Stock-Vector.jpg
Comment: According to that last image, piece geometries are not unique - so you need to combine geometric and image-matching strategies.
Answer: If your image is of sufficient quality, you can probably solve the problem looking at the pictures only when multiple pieces can fit into a given slot. The following pseudocode may work:

aquire piece outlines, using the photograph-on-a-high-contrast-background approach, and making sure to compensate for any lens distortion.
build the outer ring, by identifying all outer-ring-pieces (with one or two straight sides) and matching them shape-wise against all others. Consider a match when two pieces fit snug together: minimize (overlapArea + emptyArea), where overlapArea is the amount of overlap when the pieces are placed one after the other, and emptyArea the amount of free space between the pieces when they are placed next to each other. Break ties(and near-ties) by using color information. Matching the initial 4-corners to the image on the box should be relatively simple.
build successive rings by taking one existing ring-corner and finding the next piece to place into that corner (where a placed piece will have 2 neighbors). At the end of step 2, there will be 4 corners. After placing another piece in that corner, there will be 5. Simply continue placing pieces in corners until the last piece fits in the last space.

The geometric part of this approach requires two ingredients:

Acquire image outlines:

correcting for distortion (cameras introduce spherical distortion near the sides; plus the perspective is probably off if the photo is not taken from straight above the pieces). This is not easy in general, ask in a separate question to get some image experts involved.
use an outline-finding algorithm to find the outline-geometry for each piece. I have successfully used marching squares for this task.

To match image outlines, you can take several short-cuts to filter out bad matches. For example, matching borders must have similar lengths, and opposite orientations. Match the two corners of each pair of pieces first (which must have the same separation); then use a geometry library (I recommend JTS) to see how much they overlap, as defined by minimizing (overlapArea + emptyArea). You can find code to mix JTS and vertex-sequences here.

The image-matching part also requires two ingredients:

Prepare images for matching:

get the distortion fixed, both in piece-images and in the box-image. Also, make sure to take the box-image under the same lighting conditions as the piece-images, because otherwise the match will be more difficult. This is hard to do - again, ask in a different question if you need the details.
take a histogram of the centre pixels of each piece, using a uniform radius that guarantees that no piece-border will be included. This is rotation-invariant.
take the same histograms from a the centers-of-pieces according to the box image. Note that most jigsaws follow a fairly strict grid, with equally-spaced rows and columns. You will need to either input or detect the grid dimensions before you do this.

When deciding if a piece matches at a certain point, check compare its centre's colour histogram against the expected box-histogram for that grid position. Use, for example, mean-squared-error as a match metric. That is, if you have two pairs of red, green and blue histograms (R1, R2, G1, G2, B1, B2) with 256 values per histogram (8bbp), each of them a floating-point value counting the fraction of pixels in the corresponding circle with that pixel intensity, then square all differences and add them up to come with an error value: error = (R1[0]-R2[0])*(R1[0]-R2[0]) + ... + (B1[255]-B2[255])*(B1[255]-B2[255]).

Going geometry-only will only work if all pieces are unique, something that is in general not the case (several puzzles re-use piece outlines over and over again). Going image-only will only work if there are no repeated motifs, such as large areas of sky or trees or windows or masonry. A general approach must use both sources of information to succeed.

Edited to add in some image-matching, because geometry alone is not enough given the jigsaw examples linked by the OP
Comment: Very interesting approach. My first thought was just that it should be easier if I could (and I can) use the output image without having to write a 'blind' solving algorithm.
Comment: Quick-and-dirty matching of images will only get you so far; only certain jigsaws will be entirely image-solvable (as in: a unique position for each piece-image by matching it against the box image); and then you will need a placement-and-matching strategy similar to the above, with geometry information being more dependable than pixel-values for border-matching.
Comment: After seeing lots of non-unique-piece-geometry jigsaws, I have added in some image-matching to the mix. Nice problem, but hard to crack in a general way. If I had the time, this would be fun to try to cram into a phone app...
Comment: Thanks for your efforts, tucuxi! I'm going to start using your latest edit with the image-matching approach. I accepted your answer for all the work you put into it!
Answer: You are looking for Template Matching (finding image (puzzle piece) inside another image (the original image)).
You can iterate over your pieces and slide each one to the original image (by a step of the piece size) comparing similarity of all pixels. If you need to rotate the pieces, you need to store 4 values (orientation per position).
The maximum similarity will give you the correct position-orientation. If the pieces were cropped from the original image (and are of the same quality, relative size), you will expect to find a perfect match for each piece.
For image comparison, the simplest way is to store the aggregated RGB distance of each pixel, see here, or pHash (on java here).
Due to the fact that in a normal jigsaw puzzle, pieces are not rectangles (somehow irregular shape), when comparing, ensure that the you compare only the overlaid part of the original image (various ways to achieve that).
FYI: Solving a Jigsaw puzzle is NP-complete (see a related paper here) (imagine a worst case scenario where the image is pure green at all, no shapes, nothing; thus the output may not provide any clues :)
FYI 2: There used to be the Eternity Puzzle contest with real money prize, where winners (mathematicians) solved it in 7 months using two domestic PCs. Then Eternity II, with no winners!
So you understand this is a tough project!
Comment: This is a good starting method. There are two issues: if the orientation of the pieces isn't well known, you will need to match with rotation; and if there are repeated patterns in the image (building with windows), some of the pieces will match at different places. The computational cost is also huge.
Comment: Thank you for your answer. I haven't thought of the sliding method. On what parameters would you compare the 'similarity of all pixels'?
Comment: Also, patches of sky or tree or grass or shadow. Image matching is great for one-time features, but will eventually fail for parts of the image.
Comment: If it's a normal Jigsaw, i guess you can calibrate it to find the correct 4 horizontal-vertical positions (checking edge curvature). Even if not perfect matching, at the end you end up with some candidate positions. At this stage you have to check with your neighbors for edge matching (but now it's by far a more limited version of your problem).
Answer: First thoughts:
I would first try and add every piece in turn

geometrically (where does the piece fit tightly ?),
by colors (in case different pieces fit at the same place).

For this, you will maintain a picture where the previous pieces have been placed, with the background color being reserved.
Before trying a new piece, you have to obtain the boundary of the free area, which is a curve. (After adding a piece, the update of this curve can be made locally).
Then take a piece and choose a point on its outline. By sweeping this point on the curve, you can find a place where it fits, with a significant overlap. Keep the piece that realizes the longest fit.
In case of ties (or quasi-ties), check the colors with a similarity score such as SAD.
This will be horribly time consuming, though.

Second thought:
There is probably now way to know the exact orientation of the pieces (unless some part of the outline is guaranteed to be horizontal/vertical). Trying different angles will worsen the running time.
An alternative is to pick two points, some known distance apart on the outline of a piece. Then you slide the first point on the boundary curve and find the position of the other point, ahead on the outline and respecting the distance constraint.

Update:
If the pieces are all identical, the geometric search becomes irrelevant. But the good news is that the placement of the pieces becomes highly predictable (the pieces are just on a regular grid).
So every piece can be tried in turn at the desired place, and the correct match be based on the colors of the known image, or on the colors in the neighboring piece(s), along the common edge(s).
It is advisable to put the pieces that achieve the best match first, in order to minimize the probability of false matches.
Comment: Regarding the second side, two pieces that fit together will have to share the same corners in their common edge. So the number of combinations is limited: each piece has 4 sides, and each of those sides can fit (or not) with the 4 sides of another piece. Therefore, you only have to test 16 orientations per piece-pair, which is not too bad.
Comment: @tucuxi: at the time of my writing, there was no information about the pieces. No even "four corneredness".


Regex for truncating file name

Question: I'm having some trouble putting together a regex for trimming a file name after a certain length. This is being used to rename a large number of files simultaneously, far too many to reasonably rename by hand. Unfortunately, some of our employees like to leave notes on the end of the file name, which is what we're looking to remove.
Example file names, all of these are present and are making matching problematic.

ABC - A11B11 - Note.txt
ABC - A22B22 (Note).txt
ABC - A33B33 | Note.txt

All files will be identical in length, 16 characters specifically. The 1st section will be purely letters, specifically client account names. The 2nd section is a combination of numbers and letters, case ID numbers. The makeup of the 2nd sequence varies with each file name, but are always 6 digits long, and are always a mixture of 2 letters and 4 numbers.
I've tried using regex to pinpoint the number/letter pattern in the 2nd sequence and delete everything afterwards. I've also tried leveraging the 16 character length to delete all characters beyond 16. Unfortunately, I'm not particularly good with regex and I'm not making much headway. Most of my attempts are recognized as a valid regex search, but give incorrect match results.
Any assistance I can get on this would be greatly appreciated.
Comment: Given the input `ABC - A1B1 - Note.txt`, what is the output you expect?
Comment: Ideally, it should look like ABC - A1B1.txt. Everything after the 2nd section would need to be removed, including any trailing whitespace.
Answer: The cleanest regex replacement I can conjure up would be:
<code>Find:    ^([A-Z0-9]+ - [A-Z0-9]+).*(\.\w+)$
Replace: $1$2
</code>
Demo
This approach is to match and capture the first two portions of the file name which you want to retain.  It also captures the file extension.  Then, in the replacement, we form the new file name, effectively removing any notes which might have followed the second section of the name.
Comment: Thank you for the suggestion. I did check the demo and it seems to be working ok there, however when I drop that regex into the renaming tool I'm using, it wipes out the entire file name and returns a blank filename. I'm using the PowerRename utility that comes with Microsoft's PowerToys package. I can provide a screenshot if that's helpful.
Comment: It won't help, as I am not familiar with your tool.  Try replacing with `\1\2` or also maybe `\\1\\2`, and see if that would work.
Comment: @offspring991 Maybe this would help with the variable usage:https://learn.microsoft.com/en-us/windows/powertoys/powerrename#matching-and-variable-examples
Comment: I did try that @TimBiegeleisen, no luck unfortunately
Comment: You could also try removing the starting and ending anchors, that is, do a find on this pattern: `([A-Z0-9]+ - [A-Z0-9]+).*(\.\w+)`
Comment: @TimBiegeleisen It would be better to add the length for the 2nd sequence: `^([A-Z0-9]+ - [A-Z0-9]{6}).*(\.\w+)$`
Answer: I think I just found a working search. It's not as hands free as I was originally hoping for and will require adjusting the query for match text for different account names and do them in batches, but it works.
Find: (^ABC - A11\d{2}).*
Replace: $1
It's probably better this way anyway, making automated changes to such a wide range of business documentation makes me a little nervous. This way we can roll out changes slowly to ensure accuracy and avoid data loss or mislabeling.
Thank you for everyone that pitched in ideas.

Regex for truncating file name


Why are group policy preference drive mappings not applied to the domain administrator account?

Question: I have a working policy on my entire domain. I just found out, when logging with the domain administrator, that this policy is not applied (EDIT: Running : gpresult shows that the GPO's are applied - but, this GPO is for Drive Mappings, and the actual drive mappings are NOT shown)

The administrator account - does not have any login script on his profile tab.
To note: The mappings were applied before the GPO with a login script using the : net use ... command - all was working perfectly and correctly for the domain administrator user as well - That removes sharing and security problem (IMO)
My GPO's are mainly small/atomic settings: single GPO to handle each settings: UAC, Firewall, printers.
GPO status for the object is enabled

That's an overview of the Drive Maps:

Reading on MS support site, I checked the delegation tab, and it is marked as applied to domain and enterprise admins.

Every user gets these policies correctly.
The OU that is set is the root of the domain. (for testing purpose - I did that to eliminate hierarchy issues - did not help)

Block Inheritance is disabled. (never used it anyway)

GPO link

GPO Security Filterings
Comment: Does the OU that the Administrator account is currently located in have 'Block Inheritance' enabled?
Comment: Domain forest? Do you mean the domain root? You can't block inheritance at the forest root. Anyway, where is the Administrator account - is it in a sub-OU of the domain or just in the default Users container?
Comment: Just the default container
Comment: Ah, just seen your response  - GPOs applied at the root of the domain should apply to users in the Users container, in the same way as it would for any other OUs. Is the GPO definitely linked at the Domain root level?
Comment: Also, what is in the Security Filtering options of the GPO?
Comment: If you run a `gpresult /R` as the Domain Administrator on one of your machines, does it show any of the policies as being in the list of ones applied? Are they showing as filtered out?
Comment: In that case I think the problem is not that the GPOs aren't being applied - it's something to do with the settings within the GPO. Are other settings from the GPOs being applied as expected?
Comment: I use atomic GPO's mainly (e.g. - single settings per GPO: firewall, UAC, login, verbose...) same for the mappings *added to question
Comment: What are the Share and NTFS permissions on the shares? Do members of the Domain Admins group have the correct Share and NTFS permissions on the shares?
Comment: If I put the same shares on a login script of : net use ......   it's ok, so I don't think it's sharing and persmissions.
Comment: @Saariko: after the account logs on, if you run gupdate /force, are the drives mapped?
Comment: no they are not, as mentioned: GPO looks like it's applied, but they are not.
Answer: I suspect you are falling foul of the fact that Domain Admins are part of a special set of groups that have their ACLs reset every hour by the domain controller.
See http://support.microsoft.com/default.aspx?scid=kb;en-us;Q318180 for more details
Comment: That KB article is related to membership of Distribution Groups. Moreover, it applies to Server 2000, not 2008.


What are the options for sending legitimate bulk email?

Question: I've got a new client that wants to send batches of around 1000 emails weekly to their client list (all opt-in recipients).
Previously when I've built something for a client it has been their own mail server.
Can anyone recommend any alternatives to hosting their own mail server?
Google apps seems to have a 500 emails in 24hr limitation.
Google Groups would require recipient sign-up & wouldn't use the clients email address.
Other third party services?
Thanks.
Answer: There are hundreds of services out on the net that are fantastic for this. Here are the ones I've used or currently use and I suggest all of them. Both cost money of course but its not too bad.
Campaign Monitor
I love campaign monitor because It allows me complete freedom with the design very easily.
Mailchimp
Mailchimp has some fantastic analytics information and pretty good design functionality.
Comment: I highly recommend Mailchimp. They've got a great product, and as a bonus, a great sense of humor.
Answer: One of the advantages of using a third party service is that they can deal with any CAN-SPAM issues that may arise. My day job is to support a very large integration with a third party email vendor. The integration is very large and we send several million emails a month.
You list is relatively small, so you won't need much to make them go. I'm not that familiar with the smaller vendors, but I have heard good things about both Campaign Monitor and MailChimp. Avoid the larger companies, because they will try to lock you into a yearly contract.
The larger vendors are DREAMmail, YesMail, ExactTarget, GoodMail, Zustek, and several others.
Answer: phplist is an open source php based mailout manager. I have used it to send to around 4k addresses. Has a 'double opt-in' system that ensures people who unsubscribe stay unsubscribed.
Comment: Unrelated. He's looking for SMTP relay solutions, not for software to manage mailing lists.
Answer: You should look into some of the larger email contact list providers. There are a number that specialize in taking care of subscribers end to end and give you analytics and the like. Take a look at Exact Target, Vertical Response and maybe Webmail.us.
Answer: As a locally loaded application, I have use Maillist king Successfully for sending thousands of emails.  The pro version contains a built-in smtp server.


iOS MKPolygon pattern

Question: I searched over the internet but I couldn't find an answer to this. Is possible to draw polygon filled with some pattern? I don't wanna use 3rd party libraries. I would like to achieve something similar to this:
polygon with pattern
Answer: Yes you can do this.
UIColor has an initializer for pattern images.
guard let image = UIImage(named: "Name of the asset") else { return }
let color = UIColor(patternImage: image)

Then in your overlay renderer delegate method, you can simply assign it to your fill color.
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {

    // Renderer code

    yourRenderer.fillColor = color

    // Return your renderer

}

Comment: Thank You. This allows me for filling polygon with patter but what in case when i would like to fill polygon with pattern and have some background color?
Comment: I think the easiest way would be changing the pattern image's background color.

iOS MKPolygon pattern


Div aparece e some

Question: Criei uma div onde tem 2 links, quando a página é carregada, ambos os link estão escondidos e quando eu clicar em "buscar" eles devem aparecer. O detalhe, problema é que elas aparecem e somem! Por que isso pode estar acontecendo?
Segue o código:
<input type="submit" name="buscar" id="busca" value="Buscar">

$(document).ready (function(){
    $("#gerar").hide();

    $("#busca").click(function(){
        $("#gerar").show();
    });

});

Comment: html:
Comment: o `submit` está dentro de um `form`? é possível que após o evento `click` esteja fazendo a requisição do formulário.
Answer: Isso é chamado FOUC, flash of unstyled content. Isso quer dizer que o browser mostra o conteudo e só mais tarde vê/lê o script que o esconde, causando um flash momentâneo. E o utilizador vê, temporáriamente, esse conteudo.
A solução, e a maneira correta de fazer é usar CSS para o conteudo não estar visivel quando a página carrega, via CSS. Inline ou no ficheiro CSS.
Deve usar:

...conteudo...

ou no CSS:
#gerar{display: none;}

Comment: @GustavoSevero digo novamente: via CSS não deve haver FOUC. Coloque o seu código num jsFiddle que eu ajudo a corrigir.
Comment: Oi Sergio,
Simplesmente isso? E tiro o $("#gerar").hide(); do JQ?
Comment: @GustavoSevero exato!
Comment: Sergio, fiz o que me sugeriu <div id="gerar" style="display: none;" e não funcionou.
Comment: @GustavoSevero o que não funcionou? pode descrever o comportamento? o melhor seria partilhar o seu código para podermos ter um exemplo.
Comment: @GustavoSevero estou seguro do que sugeri. Preciso ver o seu código para perceber qual pode ser o problema...
Comment: @GustavoSevero se quiser use este para testar: http://jsfiddle.net/Ln3h53vo/
Comment:

$(document).ready (function(){
 $("#busca").click(function(){
  $("#gerar").show();
 });
});
Comment: Consegui fazer a div sumir quando é carregada a página, via CSS, mas continua aparecendo e sumindo.
E na verdade é o seguinte, quero que os links que estão dentro dessa div gerar, não apareçam, e quando um busca em uma tabela fora gerada, e mostrar os resultados, dai sim, no final do relatório, os links devem aparecer.

Div aparece e some


Conditional statement in custom template file using Display Suite

Question: I've been searching and scratching my head for a while on this one. I'm working on a blog page where the user can tag posts, but it is not required. I only want to output the label 'Category' if tags actually exist, so I need a conditional statement in my node template but I can't figure out the correct logic for doing so. This is what I have so far...
<?= if (isset($node->$content['tags'][0]['value'])): ?>

<?= t("Category"); ?>

<?= render($content['tags']); ?>

<?= endif; ?>

This code gives the following PHP error referring to the first line of the block of code
PHP Parse error:  syntax error, unexpected T_IF

I'm a Drupal novice so I'm expecting it to be something simple that I am missing or potentially just completely the wrong code.
Comment: Your server might not have been configured to allow short tags.

Try using `<?php echo` instead of `<?=`
Comment: I should have said that the short tags are fine, they are not the issue.
Answer: First, you have a syntax error. Your server might not have been configured to allow short tags.
Try using <?php echo instead of <?=
Second, you could either use the Field formatter conditions module to add display conditions to your fields or create a custom code field in Display Suite.
EDIT: How to  add a Display Suite custom code field in your own module:
1- Create a new module and add this code in it (remember to change MY_MODULE with the desired name):
/**
 * Implements hook_ds_fields_info().
 *
 * We add the code fields to Display Suite here.
 * Then we specify a callback function that will handle the display logic.
 */
function MY_MODULE_ds_fields_info($entity_type) {
  $fields = array();

  // Add a new custom code field. It should be available in Display Suite.
  $fields['node']['tags_custom'] = array(
    'title' => t('Tags (custom)'),
    'field_type' => DS_FIELD_TYPE_FUNCTION,
    'function' => 'MY_MODULE_ds_field_tags_custom',
  );

  if (isset($fields[$entity_type])) {
    return array($entity_type => $fields[$entity_type]);
  }
}

/**
 * Callback to show the tags field only if it has a value.
 */
function MY_MODULE_ds_field_tags_custom($field) {
  $node = $field['entity'];

  // Get the tags field value.
  $tags = isset($node->content['tags'][0]['value']) ? $node->content['tags'][0]['value'] : NULL;

  // Return a string or nothing, depending on the tags field value.
  if (!empty($tags)) {
    return t('Category: ') . $node->content['tags'][0]['value'];
  }
  else {
    return NULL;
  }
}

2- Now, if you go to admin/structure/ds and click on the Manage display link, you will see your new field Tags (custom). Set its label to hidden and publish it in the desired area.
Comment: Ideally I'd want the conditional statement in the template though rather than set through the admin.
Comment: You can create a custom code field in your code as well. Let me know if you need help to edit my answer accordignly.
Comment: There you go. As you can see, no changes are done in the theme, but in a custom module that will use Display Suite hooks to create a custom field (with your condition) and will make this field available via the admin.


Get average of months over years

Question: I'm trying to find the average number of 'JOBS' in each month. i.e. What are the average jobs created in the month of May  (May 2011 + May 2012 + May 2013...May 2020), the month of June, etc.
NAME CLOSEDATE  JOBS  month year
A    2019-01-01 2     1     2019
B    2019-01-01 23    1     2019
C    2018-05-24 2     5     2018
D    2019-05-23 200   5     2019
E    2020-05-23 40    5     2020
F    2020-05-14 23    5     2020
G    2020-06-12 93    6     2020

I attempted:
pd.pivot_table(proj, index=['month'],values=['JOBS'],aggfunc=[np.sum,np.mean])
which gave me average jobs per record in the month, and not the average of the aggregate month.
In the sample dataset above ideally I'd get a result of 66.25 jobs for the month of May. (2+200+40+23)/4
I feel like I'm missing something simple, or a way to format the table as:
Year Jan   Feb   Mar ..... Dec
2011 1000  4322  5322      2343
2012 3423  4322  5322      2343
...  1645  4322  5322      2343
2020 7895  3432  9999      2343
AVG. 3491  4099  6491

Comment: @wwnde thanks for noticing, I realized in my simplification for the post that I had left out two columns from my calculation. I've edited for clarification.
Comment: Please the actual dataset used. The data you have given us is missing some of the columns you used. The question therefore lacks clarity
Comment: @RichieV that gets me almost to where I need to be, I changed to ```proj.groubpy([proj.CLOSEDATE.dt.year, proj.CLOSEDATE.dt.month]).sum().unstack()``` as mean gave me the average for all records

now I just need a row that shows the average of each column
Comment: @RichieV I'm struggling with words to describe.
Pseudocode would be:

(All jobs in May2011 + All Jobs in May2012 + All Jobs in May2013)/(count of Mays)
count of Mays in this case being 3
ie the average jobs created in all Mays combined. I feel like I'm overcomplicating somehow
Comment: @RichieV that's a disconnect on my end then, yes you are correct that is divided by years. which would be the same as number of Mays in my head, assuming that there is a May in all the years
Comment: @RichieV that would be the ideal world, yes
Comment: new = proj.groupby([proj['CLOSEDATE'].dt.year, proj.CLOSEDATE.dt.month]).sum().unstack()

new.mean()

essentially gets me the answer with the JOBS row
Answer: Update
First get the sum for each year/month then average across years.
by_month = (
    proj.groupby([proj.CLOSEDATE.dt.year, proj.CLOSEDATE.dt.month]) # create the groupby object
    .JOBS.sum() # select only the JOBS column and aggregate by sum
    .unstack(0) # drop the 'year' level form MultiIndex and use as columns
    .mean(axis=1) # areage across the years we just unstacked to axis1
    .rename('avg_jobs')
    .rename_axis('month')
)

print(by_month)
month
1    25.000000
5    88.333333
6    93.000000
Name: avg_jobs, dtype: float64

This will get you the average jobs sum by month (accross years and names). Notice you can skip creating separate columns for year/month, only put them in if you want to keep using them for other calculations.
by_month = (
    proj.groupby('month') # create the groupby object
    .JOBS.mean() # select only the JOBS column and aggregate by mean
)

print(by_month)
month
1    12.50
5    66.25
6    93.00
Name: JOBS, dtype: float64

Comment: that was it! thanks for your patience and sticking with me through it
Comment: No problemo, look out for those caveats. It was hard for me when I jumped from excel to python because it is not as easy to see the data, you gotta keep a clear mental image of what you want to achieve and do thorough auditing of results

Get average of months over years


Geometry areas problem

Question: Let $BCDK$ be a convex quadrilateral such that $BC$ = $BK$ and $DC$ = $DK$.
$A$ and $E$ are points such that $ABCDE$ is a convex pentagon and $AB$ = $BC$ and $DE$ = $DC$ and $K$ lies in the interior of the pentagon.
Angle $ABC$ = 120 and angle $CDE$ = 60 and $BD$ = 2 , then determine area of the pentagon $ABCDE$.
Comment: It's listed here: http://mprakashacademy.co.in/wp-content/uploads/2014/06/RMO2001_13_.pdf  But there is a typo in your question: in the first line it is $BC=BK$.
Comment: Don't just copy the question as it is, throw in some of your work/thoughts too.
Comment: As it stands, the position of K, even given the position of all other points, is not uniquely determined, and has no bearing on the area. Are you sure you copied the question correctly?
Comment: This question is from RMO 2008
Comment: If $BC$ = $DK$ and $DC$ = $DK$ and $AB$ = $BC$ and $DE$ = $DC$ then they are all equal.  It seems a strange way to say this
Comment: I found RMO 2008 at http://rmonorthzone.com/rmo%20pdf/RMO2008.pdf but it doesn't have anything like this question.
Comment: This from RMO West Bengal region.
Comment: Anyone who doubt this can check in the back of "An Excursion in Mathematics" by S.A. Katre and Co. Its from Problem No.6 in RMO 2008.
Comment: You can upload an image to [imgur](http://www.imgur.com). Then, you can insert your image in your post such that your question get improved.
Answer: Note that $BCDK$ is a parallelogram. Because $ABCDE$ is convex, the area of $ABCDE$, shown by $S(ABCD)$, is equal to
\begin{equation}
S(ABCD) = S(ABC) + S(CDE) + S(ACE)
\end{equation}
Let's assume $CD = a$ and $BC = b$. Then, $S(ABC) = \frac{b^2\sin120}{2}$ as $AB = BC = b$ and $\hat{ABC}=120$. Similarly, we have $S(CDE) = \frac{a^2\sin60}{2}$. We use the same trick to find area of $ACE$. We get $S(ACE) = \frac{AC.CE\sin(\hat{ACE}-(30+60))}{2}$, in which 30 and 60 are angles $\hat{BCA}$ and $\hat{ECD}$ respectively (they can be found considering the fact that triangles $ABC$ and $CED$ are isosceles). Because $ABC$ and $CED$ are isosceles, we can easily show that $AC = 2b\sin60$ and $CE = a$ (in fact CED is equilateral). So, put it together we get:
\begin{equation}\begin{split}
S(ABCD) &= S(ABC) + S(CDE) + S(ACE)\\
&+ \frac{b^2\sin120 + a^2\sin60 +  2ab\sin60\sin(\hat{ACE}-90)}{2}
\end{split}
\end{equation}
Considering the fact that $\sin120 = \sin 60$ and $sin(\hat{ACE}-90) =-\cos(\hat{ACE})$, we get
\begin{equation}
S(ABCD) =  \frac{b^2 + a^2 -  2ab\cos(\hat{ACE})}{2}\sin60
\end{equation}
Using the law of cosines, numerator is $BD^2$ which is 4. Thus, $S(ABCD) = 2\sin(60) = \sqrt3$.
Comment: $BCDK$ is NOT a parallelogram, in general.
Comment: The question is modified apparently, and my solution may not be true for the new version.

Geometry areas problem


Problem with Sequences..

Question: I'm having trouble with a homework question, and cant see where im going wrong.
The question is as follows:
Let $x\gt1$ and let $a_n = 1+\frac 1x+\frac 1{x^2} + \cdots + \frac 1{x^n}$ for all $n\ge1$.
(i) Prove that $a_{n+1} \gt a_n$ for all $n\ge1$.
(ii) Prove that $a_n\lt \frac x{x-1}$ for all $n\ge1$.
(iii) Prove that ($a_n$) is convergent.
Part (ii) and (iii) are fine. Just part (i)
Comment: $$a_{n+1} - a_n = \frac{1}{x^{n+1}} > 0$$
Comment: $a_{n+1}$ is $a_{n}$ plus something positive:  $a_n=\sum_{i=0}^n\frac{1}{x^i}$, so $a_{n+1}=\sum_{i=0}^{n+1}\frac{1}{x^i}$.
Comment: $\frac{1}{x}$ cancels too. Why do you start with $\frac{1}{x^2}$?
Comment: Never mind. I just copped what i was missing. I'm a fool.
Comment: $a_{n+1}=1+\frac{1}{x}+\frac{1}{x^2}+\cdots +\frac{1}{x^{n+1}}$
Comment: I have found that the block from $$\frac 1{x^2}$$ to $$\frac 1{x^n}$$  plus the 1 cancel in both sides.
This leaves with $$\frac 1{x^{n+1}} \gt \frac 1x$$
Comment: in $a_{n+1}$ how is there a $\frac 1x$ term? I think this is where im getting confused...
Answer: a) $a_{n+1}=a_n+\frac{1}{x^{n+1}}$ and the last one is greater than $a_n$, being
$\frac{1}{x^{n+1}}>0$.
Comment: I'm glad you understood!
Comment: in $a_{n+1}$ is the $n=1$ term not $$\frac 1{x^2}$$ Thus leaving a $\frac 1x$ in $a_n$ that doesn't cancel?
Comment: Sorry but I don't understand your problem. Can you be clearer, please?
Comment: I thought the whole sequence changes, but copped that its only an extra term added to the end. It's just very early and I must not be fully awake it seems.. Thanks for the answer though! It helped me cop on

Problem with Sequences..


Can we get confidence intervals for entries in stationary vector for an absorbing, time-independent Markov chain?

Question: I have a finite-state, time-independent Markov chain with two absorbing states which models educational outcomes (the absorbing states are completing and not completing). The transition probabilities are estimated by taking the proportions of people who move from one state to another at successive time points (based on a census of the population at two successive time points), and I have calculated the stationary vector.
However, since this needs to be done with several different cuts of the data, I would like to know if there is any way of associating a confidence interval to the entries of the stationary vector, to aid in identifying significant differences.
The article

Karson, M. J. and Wrobleski, W. J. (1976),
   CONFIDENCE INTERVALS FOR ABSORBING MARKOV CHAIN PROBABILITIES APPLIED TO LOAN PORTFOLIOS. Decision Sciences, 7: 10–17. doi: 10.1111/j.1540-5915.1976.tb00653.x

looks helpful, but I'm not sure if it what I need. So my questions are:

Is there a way to estimate confidence intervals for the stationary vector?
If yes,  and it is in the cited article, do I just need to grit my teeth and push through it, or is there a more modern treatment?
(a long shot, but could save me some work) Is there is a macro or similar for SAS to estimate said confidence intervals?
Comment: @David Are you sure you want to remove it? I think it should stay because it still may be useful for other people.
Comment: Since the Markov chain you consider has some absorbing states (and is irreducible, presumably), its stationary distribution is concentrated on these absorbing states. In other words, the stationary vector you computed should have exactly two non zero coordinates, one for each of the absorbing states. Is this really what you have in mind?
Comment: Yes. The issue is computing some confidence intervals for said entries.
Comment: I'm asking the moderators to close this as no longer relevant.
Comment: I don't want to delete it, but close it (on MathOverflow there's a difference, but they don't run SE2.0). I'm happy to leave it as is for the sake of posterity, but I've realised my problem is not what I was asking in this question.
Comment: So you could accept my answer if it fits your question as you asked it, then open a new question on stats.SE with what you really are interested in.
Comment: Yes, I know what my options are :) Unfortunately the real problem is not a statistical one....
Answer: So, as said in the comments, the Markov chain you consider has some absorbing states (and is irreducible, presumably), hence its stationary distribution is concentrated on these absorbing states. Therefore the issue is to compute some confidence intervals for the only two non zero coordinates of the stationary vector, one for each of the absorbing states. I would call these entries absorption probabilities rather than stationary vector because there is not much really stationary here, but anyway...
Since there are two absorbing states, $a$ and $b$ say, you are interested in $u_c=P_c[$The chain is absorbed at $a]$, for a given initial state $c\ne a$, $b$. I gather you observe the number $N_t(x)$ of particles at state $x$ and time $t$, for every state $x$ (or every $x\ne a$, $b$?), at two different times $t_1$ and $t_2$. How to estimate $u_c$ from these counts? Surely I am missing the obvious but, even replacing (a multiple of) each $N_t(x)$ by the exact value of $P_c[$The chain is at $x$ at time $t]$, I do not see how to compute $u_c$ from these quantities.
Dimensional analysis shows that for $n$ states, $N_t(x)$ at every state $x$ and two different times yields $2(n−1)$ independent parameters and the transition matrix has $n(n−1)$ independent parameters, a fact which seems to indicate that it would be impossible to identify the latter from the former as soon as $n\ge3$. OK, this argument is too sloppy to be really conclusive but...
(Caveat: I did not read, and have no access to, the paper by Karson and Wrobleski.)
Comment: it is possible to estimate the probability of absorption in a given state given any initial distribution if you have the transition matrix. The entries of the transition matrix are estimated as you say, but you forget that in the presence of $m$ absorbing states you don't have $n(n-1)$ parameters but $(n-1)(n-m)$ (at least by my rough count), so for 4 states and 2 absorbing states, you have exactly enough parameters to estimate the transition matrix (and in my case there are further constraints which cut down the number of parameters needed - this is immaterial)
Comment: See e.g. http://math.furman.edu/~tlewis/math110/maki/chap8/sec4handout.pdf for a quick discussion of calculating absorption probabilities.
Comment: David: I was not aware that the situations you were interested in involved such small values of $n$ (and you are right, the number of parameters is $(n-1)(n-m)$). May I ask why you now want this question closed? Did you solve the question? I note that there is nothing in the handout you refer to about the *estimation* problem you asked.
Comment: I've realised that what the paper cited shows is not really what I need. The paper deals with absorption probabilities calculated from samples, whereas I have complete information, and the uncertainty is not in how well I can guess the true values of the model given incomplete information, but the fit of the model to reality.


Irreducibility is preserved under base extension

Question: I want to prove that if $A$ is a finitely generated $k$-algebra ($k$ is a field) with prime nilradical then for any field extension $k\rightarrow K$, the $K$-algebra $A\otimes_kK$ has also prime nilradical, that is, if for some $f,g\in A\otimes_kK$ we have $(fg)^n=0$ for some $n$ then we must conclude that $f^n=0$ or $g^n=0$ for some $n$.
I am considering the case $K=\overline{k}$. First I take an algebraic extension $K$ which is purely inseparable over $k$. If $f\in A\otimes_kK$ then it is easy to show that $f^{p^n}\in A$ for some $n$ ($p=Char\ k$) and with this observation it is easy to conclude that $A\otimes_kK$ has prime nilradical in this case. Now if I could conclude the proof in the case where $K$ is a finite separable extension then I am done because taking $K=k_s$, where $k_s$ is the separable closure of $k$ then it is not difficult to conclude that $A\otimes_kk_s$ has prime nilradical and finally I can use the observation that $\overline{k}$ is a purely inseparable extension of $k_s$.
A final observation is that if $k\rightarrow F\rightarrow K$ are extensions and if $A\otimes_kK$ has prime nilradical then $A\otimes_kF$ has prime nilradical. So the problem can be reduced to:
If $A$ is a finitely generated $k$-algebra with prime nilradical and if $K$ is a finite Galois extension of $k$ then $A\otimes_kK$ has prime nilradical.
Any help with this problem will be strongly appreciated.
Comment: Since Jim has pointed out, that the claim is wrong, it may be helpful why you want to prove this, and what additional assumptions ($k$ algebraically closed will suffice) are available in your situation.
Comment: I am sorry, I did a bad interpretation of Hartshorne's Exercise 3.15 in chapter 2.
Answer: This is true for example when $k$ is algebraically closed (and this one the main steps in the exercise in Hartshorne's book mentioned in the comments). In fact, the following is true:

If $k$ is an algebraically closed field and $X,Y$ are irreducible (integral, reduced) $k$-schemes, then the same is true for $X \times_k Y$.

Proof sketch: For "integral", first do the affine case: Let $A,B$ be integral $k$-algebras, we have to show that $A \otimes_k B$ is integral. By a colimit argument, we may assume that $A,B$ are finitely generated. By Hilbert's Nullstellensatz, $A \to \prod_{\mathfrak{m}} A/\mathfrak{m}$ is injective, where $\mathfrak{m}$ runs through the maximal ideals of $A$, and in each case we have $A/\mathfrak{m}=k$. The same for $B$. Now if $x,y \in A \otimes_k B$ with $xy=0$ and $y \neq 0$, choose some maximal ideal $\mathfrak{n} \subseteq B$ with $0 \neq y \bmod \mathfrak{n}$. For all $\mathfrak{m} \subseteq A$ it follows that $0 = (x \bmod \mathfrak{m})(y \bmod \mathfrak{n})$ in $A/\mathfrak{m} \otimes_k B/\mathfrak{n}=k \otimes_k k=k$, hence $0 = x \bmod \mathfrak{m}$. This shows $x=0$.
For "reduced", reduce to the affine case, and then a similar argument as above works, see here.
For "irreducible", first do the affine case: Let $A,B$ be $k$-algebras such that $A_{red},B_{red}$ are integral. We already know that $A_{red} \otimes_k B_{red}$ is integral, in particular irreducible. Now apply the Lemma below twice to conclude that $A \otimes_k B$ is irreducible. For the general case of two $k$-schemes $X,Y$, it is not hard to show that the generic points of the affine charts coincide, by considering their intersection.
Finally, integral = reduced + irreducible. $\square$

Lemma: For $S$-schemes $X,Y$ the canonical morphism $(X \times_S Y)_{red} \to X_{red} \times_S Y$ is a homeomorphism.

In fact, one can check (for example in affine charts) that this morphism is a closed immersion whose ideal is nil.
Comment: In the first paragraph after your main statement, it seems that you are assuming $x$ of the form $a\otimes 1$ and $y$ of the form $1\otimes b$.
Comment: To fix it, we can use the fact that if $X\subseteq \mathbb{A}^n$ and $Y\subseteq \mathbb{A}^m$ are affine varieties then $X\times Y\subseteq \mathbb{A}^{n+m}$ is also an affine variety whose coordinate ring is $A(X)\otimes A(Y)$.
Comment: My proof does not need any adjustment. $x,y$ are in the tensor product. But when I write modulo some ideal in $B$, I mean modulo the ideal generated by it in $A \otimes B$.
Comment: And the proof of this fact can be followed from Hartshorne's book, Chap 1, exercise 3.15
Comment: Martin, can you clarify with respect to Diego's question? Is $x \in A \otimes B$ or in $A$?
Comment: In that case, wouldn't $y\text{ mod }\mathfrak{n}$ be an element of $A\otimes B/\mathfrak{n}$ rather than simply an element of $B/\mathfrak{n}$? Because then $y\text{ mod }n$ might be zero in $A/\mathfrak{m}\otimes B/\mathfrak{n}$, so that we do not have $x\text{ mod }\mathfrak{m}=0$ for all $\mathfrak{m}$.
Answer: The $\mathbb R$-algebra $\mathbb R[x]/(x^2 + 1)$ has prime nilradical but $\mathbb C[x]/(x^2 + 1)$ does not.


Same rotated component matrix in Factor Analysis despite using different data normalizations

Question: I'm using SPSS for factor analysis with these options:
FACTOR
  /VARIABLES VAR00001 VAR00002 VAR00003 VAR00004 VAR00005 VAR00006
  /MISSING LISTWISE
  /ANALYSIS VAR00001 VAR00002 VAR00003 VAR00004 VAR00005 VAR00006
  /PRINT UNIVARIATE INITIAL CORRELATION SIG DET KMO INV REPR AIC EXTRACTION ROTATION
  /PLOT EIGEN ROTATION
  /CRITERIA MINEIGEN(1) ITERATE(25)
  /EXTRACTION PC
  /CRITERIA ITERATE(25)
  /ROTATION VARIMAX
  /METHOD=CORRELATION.

Before inserting data to the software I normalized (and in one case standardize) data:

Using values-min/max-min transformation.
Using values A as denominator of all features.
Using B values (different with A) as denominator of all features.
Using C values (different with A and B) as denominator of all features.
standardize data using mean and std.
Using Raw data as input of factor analysis of SPSS.

Output of SPSS:
Rotated Component Matrix
              Component
              1       2
VAR00001    .973    -.062
VAR00002    .911    -.134
VAR00003    .833    -.035
VAR00004    .972    -.102
VAR00005    -.236   .823
VAR00006    .062    .878
Extraction Method: Principal Component Analysis.
 Rotation Method: Varimax with Kaiser Normalization.
a Rotation converged in 3 iterations.

In all cases I have same Rotated Component Matrix (other reports are same too)! Why? Is this a bug or because of Correlation Method or VARIMAX rotation?
Answer: It seems (/METHOD=CORRELATION) that you are asking SPSS to perform FA on the correlation matrix (actually by typing /EXTRACTION PC you seem to be performing PCA and not FA, but it does not matter for this question).
Correlation matrix does not change if you scale individual variables, so any amount of normalizing or standardizing would not change it. You can think of it as if all the variables are automatically standardized to have zero mean and unit variance prior to the PCA/FA analysis. No wonder you always get the same result.
Varimax rotation has nothing to do with it.


Iframe escondendo conteúdo

Question: Tenho um iframe que recebe "interacoes.php" que é um select.
Mas o iframe esconde os conteúdos por conta do height="100%". Se eu coloco height=20000px; ele mostra tudo.
Como posso fazer pra aparecer tudo automaticamente?
Não quero colocar um height fixo, por que tanto faz o conteúdo ser pequeno ou grande, vai de acordo com oque tem no select.
HTML:

Comment: Você poderia habilitar o scrolling?
Comment: Obrigado por responder gabriel. Não seria ideal habilitar o scroll. O interessante é o height automatico :/
Answer: Se você deseja que o conteúdo dentro do iframe seja exibido automaticamente, sem que seja necessário definir manualmente uma altura específica, você pode adicionar o seguinte JavaScript ao seu arquivo HTML:
php

  function autoResize(id){
    var newheight;
    var newwidth;

    if(document.getElementById){
      newheight=document.getElementById(id).contentWindow.document.body.scrollHeight;
      newwidth=document.getElementById(id).contentWindow.document.body.scrollWidth;
    }

    document.getElementById(id).height= (newheight) + "px";
    document.getElementById(id).width= (newwidth) + "px";
  }

E então adicione o atributo "id" ao seu iframe, para que o JavaScript possa identificá-lo:
bash

Isso fará com que a altura e a largura do iframe sejam ajustadas automaticamente de acordo com o conteúdo que ele está carregando.

Iframe escondendo conteúdo


Picture does not appear after successfully uploading it

Question: so today I was trying to upload photo from admin file to user file. One thing I discovered is that my code works fine, but something is a little bit wrong I don't know where. When I successfully uploaded the picture, the picture didn't appear. But it successfully been uploaded. Could you help me out?
This is the code I used to upload the picture
         <?php
          require_once ('db/database.php');

          if(isset($_POST['submit']))
          {
            $name = basename($_FILES['file_upload']['name']);
            $t_name = $_FILES['file_upload']['tmp_name'];
            $dir = 'fotovid';
            $kat = $_POST['kat'];
            if(move_uploaded_file($t_name, $dir."/".$name))
            {
              mysqli_select_db($koneksi, 'koneksi_oop');
              $query = "INSERT INTO gallery (id_gambar, kat_gambar, nama_gambar, path) VALUES ('', $kat, '$name', 'fotovid/$name')";
              $res = mysqli_query($koneksi, $query);
              echo "Berhasil upload foto";
            } else {
              echo "Gagal upload foto";
            }

          }
        ?>

                     <form action="inputfoto.php" method="post" enctype="multipart/form-data">
                    <input type="file" name="file_upload" />

                    Kategori
                    <input type="text" name="kat">

                    <input type="submit" name="submit" value="Upload">
                </form>

While this is the class where I call 2 categories from database, which is 'Foto' and 'Video'.
   <?php
    include ('admin/db/database.php');
        $query = "SELECT * FROM kategori_gambar";
        $res = mysqli_query($koneksi, $query);
        while ($row=mysqli_fetch_array($res))
        {
    ?>

            <fieldset style="margin:0px 40px 100px 40px;">
                <legend>

                    <a href="keluar_gambar.php?kat_gambar=<?= $row['id'];?>">
                        <?php
                            echo $row['nama'];
                         ?>

                </legend>
            </fieldset>

        <?php
            }
        ?>

And the last one is where the output should comes out.

                $query = "SELECT * FROM gallery WHERE kat_gambar =".$_GET['kat_gambar'];

                $res = mysqli_query($koneksi, $query);
            ?>

            <!DOCTYPE html>

                <title></title>

            <?php
                while($row=mysqli_fetch_array($res))
                {
            ?>
                <img src = "<?php echo $row['path']; ?>" width='300px' height= "200px" />

                <?php
                    }
                ?>

This is what happened when I tried to insert the image
enter image description here
enter image description here
enter image description here
enter image description here
Comment: Do you reach the picture by visiting its url in the address bar of a browser?
Comment: I tried, but the picture seems to come out in a weird way,  like this -> https://i.stack.imgur.com/QGmyU.png @whiteletters in blankpapers
Comment: So the url is not the correct address to reach the pictur. Are you sure the photo is correclty uploaded first?
Comment: yes I do, but let me check it out again
Comment: Please to try to get the url of the uploaded picture and put it in the href
Comment: still didn't work
Comment: can you point out in my code which one should I change?  @whitelettersinblankpapers
Comment: Sorry for delay.  Nice to see that you found the solution :)
Answer: I think there is a permission issue. could you please show us the output of the following code.
$row=mysqli_fetch_array($res)

and also check the folder where you tried to upload.
Comment: I managed to solve my problem. It is the directory problem. Anw, thanks for your respond mate.


só ocupa as 3 primeiras colunas criadas no CSS Grid. Como faço para ocupar as 4 colunas da tela?

Question:

body {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  background-color: white;
}

div.container {
  display: grid;
  grid-template-columns: 3fr 1fr;
  grid-template-rows: 20vh 70vh 10vh;
  grid-template-areas: "h h" "m a" "f f";
}

header {
  background: yellow;
  grid-area: h;
}

main {
  background: blue;
  grid-area: m;
}

aside {
  background: green;
  grid-area: a;
}

footer {
  background: red;
  grid: f;
}
<!DOCTYPE html>

  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Site</title>
  <link rel="stylesheet" href="style.css">

Estou aprendendo CSS-Grid e não consigo descobrir o porquê o footer não ocupa as 4 colunas criadas, apenas as 3 primeiras. Alguém pode me ajudar, prf?
Answer: footer está com o atributo grid ao invés de grid-area, este é o problema!

body {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  background-color: white;
}

div.container {
  display: grid;
  grid-template-columns: 3fr 1fr;
  grid-template-rows: 20vh 70vh 10vh;
  grid-template-areas: "h h" "m a" "f f";
}

header {
  background: yellow;
  grid-area: h;
}

main {
  background: blue;
  grid-area: m;
}

aside {
  background: green;
  grid-area: a;
}

footer {
  background: red;
  grid-area: f;
}
<!DOCTYPE html>

  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Site</title>
  <link rel="stylesheet" href="style.css">