All routes resolve to entity.user.edit_form for authenticated users

Question: This is a new one for me:
All routes, for an authenticated user, resolve to entity.user.edit_form.
Anonymous users are able to browse all public-facing pages of the site without any problems.
This is the route:
$ ddev drush core:route --name=entity.user.edit_form
name: entity.user.edit_form
path: '/user/{user}/edit'
defaults:
  _entity_form: user.default
  _title_callback: 'Drupal\user\Controller\UserController::userTitle'
requirements:
  user: \d+
  _entity_access: user.update
options:
  _admin_route: true
  parameters:
    user:
      type: 'entity:user'
      converter: paramconverter.entity
  _access_checks:
    - access_check.entity

There doesn't seem to be anything wrong with this particular route -- it's all the other ones that don't behave as expected.
For what it's worth:
Drupal version   : 9.4.5
PHP version      : 7.4.30

The problem surfaced on a remote production site running on Microsoft Azure (Kudu / IIS); I have imported its database, for testing purposes, into a DDEV-Local environment (Docker / Linux).
In the remote environment, the following route-related errors appeared in the dblog:
$ ddev drush ws
 --------- -------------- ------------------ ---------- -------------------------------------------------
  ID        Date           Type               Severity   Message
 --------- -------------- ------------------ ---------- -------------------------------------------------
  5692475   04/Oct 20:10   php                Error      Symfony\Component\Routing\Exception\RouteNotFou
                                                         ndException: Route "devel.configs_list" does
                                                         not exist. in
                                                         Drupal\Core\Routing\RouteProvider->getRouteByNa
                                                         me() (line 206 of D:\home\site\wwwr
  5692474   04/Oct 20:10   php                Error      Symfony\Component\Routing\Exception\RouteNotFou
                                                         ndException: Route "devel.configs_list" does
                                                         not exist. in
                                                         Drupal\Core\Routing\RouteProvider->getRouteByNa
                                                         me() (line 206 of D:\home\site\wwwr
  5692473   04/Oct 20:10   php                Error      Symfony\Component\Routing\Exception\RouteNotFou
                                                         ndException: Route "devel.configs_list" does
                                                         not exist. in
                                                         Drupal\Core\Routing\RouteProvider->getRouteByNa
                                                         me() (line 206 of D:\home\site\wwwr
  5692472   04/Oct 20:10   php                Error      Symfony\Component\Routing\Exception\RouteNotFou
                                                         ndException: Route "devel.configs_list" does
                                                         not exist. in
                                                         Drupal\Core\Routing\RouteProvider->getRouteByNa
                                                         me() (line 206 of D:\home\site\wwwr
 --------- -------------- ------------------ ---------- -------------------------------------------------

In the DDEV-Local environment, I executed the following commands:
$ ddev drush eval '\Drupal::service("router.builder")->rebuild();'
$ ddev drush cr
 [success] Cache rebuild complete.

After rebuilding the routes, the error no longer appears in the logs; however, all routes now arrive at the logged-in user's profile edit form.
In comments, @jaypan said:

Disable the devel module and any devel related modules, and see if that resolves it.

This is a good suggestion. Those modules are already disabled:
$ ddev drush pml |grep devel
  Development                          Devel (devel)                           Disabled   4.1.3
  Development                          Devel Generate (devel_generate)         Disabled   4.1.3
  Webform                              Webform Devel (webform_devel)           Disabled   6.1.2

They are present in the composer.json:
$ grep devel composer.json
        "drupal/devel": "^4.1",
        "drupal/devel_generate": "^4.1",

I am able to enable them without error:
$ ddev drush en devel devel_generate
 [success] Successfully enabled: devel, devel_generate

This does not fix the routes.
I am able to disable them without error:
$ ddev drush pmu devel devel_generate
 [success] Successfully uninstalled: devel, devel_generate

This also does not fix the routes.
The previous developer was unable to use Drush in this environment and appears to have been using raw SQL queries to clear caches (truncate all the cache tables) and disable modules. The errors are quite likely related to that approach.
Update (2022-10-07)
In comments, @cilefen asked:

Did any known platform or codebase change precipitate this? Are any custom modules installed? Is there a version control log? Have you restored from backups to identify when or how this changed?

I still do not have access to the client's VPN, so I can't access their version control repositories directly. We have restored the database from backups that predate the problem, so I now think the problem may be caused by Azure DevOps being configured to deploy the built artifact on top of the previously-installed files.
Troubleshooting from another angle, I have used curl to capture an authentication cookie:
$ curl --cookie cookie.txt --cookie-jar cookie.txt $(ddev drush uli)

Now, when I use curl to request a page as an authenticated user, I receive this:
$ curl --cookie cookie.txt https://clientsite.ddev.site
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   414    0   414    0     0   3568      0 --:--:-- --:--:-- --:--:--  3568
<!DOCTYPE html>

        <meta charset="UTF-8" />
        <meta http-equiv="refresh" content="0;url='https://clientsite.ddev.site/user/1/edit'" />

        <title>Redirecting to https://clientsite.ddev.site/user/1/edit</title>

        Redirecting to https://clientsite.ddev.site/user/1/edit.

%

This appears to show that the redirect is caused by <meta http-equiv="refresh" content="0;url='https://clientsite.ddev.site/user/1/edit'" /> rather than by corruption in the routing table.
I hope I'm getting close to resolving this. (If not, I might add a bounty to the question in 10 hours!)
Comment: Disable the devel module and any devel related modules, and see if that resolves it.
Comment: Did any known platform or codebase change precipitate this? Are any custom modules installed? Is there a version control log?
Comment: IIRC I ran into this issue with custom entity which has wrong parameters in routing.yml parameters:
    user:
      type: 'entity:user'
This might be causing it.
Comment: It makes sense that the previous developer got into trouble with routes when only truncating the cache tables because routes are stored in a different database table. A cache clear, either in UI or via Drush, includes rebuilding the router table, so you don't need the extra step.
Comment: Now that you have removed Devel properly, can you provide some details about the second problem? Is Drupal redirecting to the user edit form when you check the responses in the F12-tools of your browser?
Comment: Have you restored from backups to identify when or how this changed?
Comment: Good idea @Jaypan! See my edited answer above for my full response.
Comment: Thanks for all the great responses. @cliefen I've restored a database backup from just before the remote site crashed, and I may try to restore an earlier one next. As for the codebase, I'm still waiting for VPN access to the client's GitHub Enterprise repositories; meanwhile, I have a tarball of the Production build artifact (not including git metadata) from the Azure DevOps folks. Another possible angle: some contrib modules are duplicated under `./modules/` and `./modules/contrib/` (they are not using `drupal/recommended-project`). So I've got many options for fixing things. :)
Answer: I figured out what was causing the redirect, and it was something perfectly normal and obvious: the Password Policy module.
I had been using drush uli to log in as User 1, but the site had a password expiry policy, and User 1 had not logged in for a long time ... so its password was expired.
I'm just so used to ignoring the message that says "change your password" that I didn't read it :)
Resetting the User 1 password made the redirect go away.
I might open an Issue Queue for Password Policy to suggest that the module should implement a different route to reset the password, rather than re-using the default profile edit page.


window.enableMouseFlow is undefined in componentDidMount() but available in render()

Question: Hi I have this piece of code
    export class CompanyAccountsList extends Component {
        constructor(props) {
            super(props);
        }

        getChildContext() {
            return { prefix: 'company_accounting' };
        }

        componentDidMount() {
            //getting window.enableMouseFlow in this console
            console.log(window);

            //can't get window.enableMouseFlow in this console
            console.log(window.enableMouseFlow);

            if (window.enableMouseFlow) {
                //This codes are never executing as the condition is undefined
                enableMouseFlow();
                setMouseFlowTag('new_company_accounting');
            }
        }

        render() {
    //Rendering codes are here
    }

On initial load of the page I am getting the result as
Window {postMessage: ƒ, blur: ƒ, focus: ƒ, close: ƒ, frames: Window, …} CompanyAccountsList.jsx?a48a:36
undefined

In the consoled 'window object' 'enableMouseFlow' is available but when I am trying to get it as console.log(window.enableMouseFlow); it is consoling as 'undefined'
If I console it in the render() method I am getting the result as:
ƒ () {
          sessionStorage.setItem('mf_start', '1');
          activateMouseflow();
      }

So as summation, I can't find 'window.enableMouseFlow' in the componentDidMount()
Answer: I think console.log is passing a reference to window, and so it may be resolved at the time of it's actual log to the console.
You could try
const x = JSON.stringify(window);
console.log(x);
(I think that'd give you window at the time of componentDidMount)
But I'm guessing that enablemouseflow is something that gets added to window after the creation of the page in some other script, so it's not actually available for this component. (but would be available at render).
Answer: @Alan Yes actually I'm getting window in componentDidMount, even If I console window I can get enableMouseFlow in console.
console.log(window);

Output:
//window.enableMouseFlow is available

but if I only console window.enableMouseFlow I'm getting it as undefined
console.log(window.enableMouseFlow);

Output:
//Undefined
////window.enableMouseFlow is not available

Secondly, yes I am thinking same as you enablemouseflow is gets added to window after the creation of the page in some other script but I have some other similar reactJs pages where I can get console.log(window.enableMouseFlow) in the componentDidMount
FYI, after populating the page in the browser console I can get console.log(window.enableMouseFlow);
Actually window.enablemouseflow is loading a bit later actually, see the screenshot:
console screenshot
Comment: Hmm... so, we're agreed on what's happening. window.enableMouseFlow is being loaded later (maybe in a sibling component to this one, and other components may have that enablemouseflow enabler as their parent component, which is why it's in the constructor for them).

It seems like anything you want to do with `window.enableMouseFlow` you could just happen in `render()` no?


Query with Min and Max results from Subquery

Question: I need help with a sql query.  I'm using Sql Server Management Studio, and the relevant fields are:
Employees.Id

Employees.Name

Events.Employee_Id

Events.DateTime

What's the most efficient way to return one record for each employee / date (not DateTime) combination, with Name, min(DateTime), max(DateTime), and the delta in hours for each employee / date combination?
Answer: Simple way would be using Join with Min/Max aggregate
select e.Name,Min(ev.[DateTime]),Max(ev.[DateTime])
from Employees e
Left join Events ev  --change it to INNER JOIN if you don't want all the employees
ON e.Id = ev.Employee_Id
Group by e.Name

Another approach using Apply operator
select e.Name,oa.MinDate,oa.MaxDate
from Employees e
Outer Apply( --change it to Cross Apply if you don't want all the employees
            select Min(ev.[DateTime]),Max(ev.[DateTime])
            from Events ev
            Where e.Id = ev.Employee_Id) oa (MinDate,MaxDate
            )

Answer: Thanks so much for the responses.  The question must not have been clear because you both of your solutions were similar, but not what I was looking for.  They did get me to go back and try again from scratch, and I'm not sure why I didn't try this in the first place, but below is returning the results I was looking for.  In my question I had changed the table/field names and omitted requirements I knew I could achieve myself in order to keep the question as simple and readable as possible, which is why this looks so different:
SET DATEFIRST 1
SELECT e.IdEmpNum,
       m.tFirstName,
       m.tLastName,
       convert(varchar(10), e.dtEventReal, 101) as "event_date",
       convert(varchar(20), min(e.dtEventReal), 108) as "min",
       convert(varchar(20), max(e.dtEventReal), 108) as "max",
       round((datediff(minute,
                 min(e.dtEventReal),
                 max(e.dtEventReal)
       )/60.0), 2) as "hours"
FROM tblEvents e INNER JOIN tblEmployees m ON e.IdEmpNum = m.iEmployeeNum
WHERE e.dtEventReal >= dateadd(day, 1-datepart(dw, getdate()), convert(date,getdate()))
GROUP BY e.IdEmpNum, m.tFirstName, m.tLastName, convert(varchar(10), e.dtEventReal, 101)
ORDER BY e.IdEmpNum, convert(varchar(10), e.dtEventReal, 101) ASC;

DATEFIRST and the WHERE conditions specifies that only events from this week are returned.  The only problem I'm having now is summing the "hours" calculation.  I'm getting an error, "SQL Server Cannot perform an aggregate function on an expression containing an aggregate or a subquery".
Answer: Window functions should be the most efficient method.  Assuming that there is already one row per name and date/time:
select e.*,
       max(e.datetime) over (partition by name),
       min(e.datetime) over (partition by name),
       (datediff(hours,
                 min(e.datetime) over (partition by name),
                 max(e.datetime) over (partition by name)
       ) as diff_in_hours
from events e;


How to "restart" particular network interface on RHEL?

Question: In RHEL, instead of using service network restart command, how can i restart a particular network interface, lets say "eth1", with only one command.
"Only one command" because that is the only interface where my ssh is working on also. So if i'm about to use: ifdown and then ifup, i will never be able to hit the ifup command as my ssh has been terminated once after ifdown eth1 command.
So there should be a single command which allows me to altogether bring down and then bring up the interface which is serving my current ssh connection. So i do not need to worry about connection totally lost to my server.
Any idea please?
Answer: You can use:
ifdown eth1 && ifup eth1

As a single command. The && just runs one command, then the other if the first command succeeds.  If you are required to use sudo make sure you use it before each command:
sudo ifdown eth1 && sudo ifup eth1

As long as your interface is configured to have the neccessary IP and route to match the current configuration, your ssh connection won't drop.
If you're worried about using it on a production server that you don't have another method of access to, that's understandable. Though the command does exactly what you want, it's very easy to have a configuration error that is only noticed after running this command. If you don't have an alternate method of access (for example, out-of-band console, or SSHD running on another interface), it's safest not to do this.
I use this technique often to perform a 'restart' of the interface, but I generally have a backup method of access available just in case when I do it.
Comment: Might I suggest `ifdown eth1 && ifup eth1`, this way ifup doesn't run unless ifdown was successful, whereas with a `;` ifup will run regardless of how ifdown returned.
Comment: this plus OOB management FTW
Comment: @zamnuts Answer now edited to include this  :)
Answer: You can 'restart' one interface by issuing following commands:
# ifdown eth1
# ifup eth1

After that, you can verify that your new configuration is active
# ip a

Comment: will this help? `ifdown eth1 ; ifup eth1` ?
Comment: Sorry but i need .. "Only one command" because that is the only interface where my ssh is working on also. So if i'm about to use: ifdown and then ifup, i will never be able to hit the ifup command as my ssh has been terminated once after ifdown eth1 command.

So there should be a single command which i can bring down and then bring up the interface which is serving my current ssh connection. So i do not need to worry about connection lost to my server.
Comment: You could make them a shell script and run that, your ssh-session should not get terminated, even though there will be short network blackout. Other option is to run that script inside of screen-session, where it will be executed to the end, even if your ssh-session would fail.
Answer: Are you trying to change the IP address (or any interface parameter for that matter) of an interface on a remote machine? If the answer is yes, then you can try one of the following:
A cool method is by using the screen utility to create a session by just typing 'screen'. Once you restart the network service and your SSH connection drops, use screen -ls to check that the session is still active (but detached) and screen -r to resume the detached session. This will work in case there is no error in your interface configuration file, i.e. the network service is restarted successfully.
You can also use the following trick:
$ cp -v current_conf_file current_conf_file.bak
$ echo "mv current_conf_file.bak current_conf_file && service network restart" | at now+10min

And proceed with editing your interface configuration file and restarting the network service. In case of a mistake, you just have to wait 10 minutes, in order for the previous configuration to be reapplied and the network service to be restarted.
Answer: all answers talking about ifup & ifdown are not according to the question. ifup & ifdown just bring the interface up and down only, it doesn't effect the network service. for linux network service doesn't mean interfaces ip setup only.
please check /etc/rc.d/network script for more details.
Comment: I'm not sure what point you're making.  The OP doesn't ask about restarting the network *service*, but only restarting an individual *interface*.  Moreover, the OP has accepted an answer that explicitly uses the commands you're recommending against.  -1 from me.


Failing to read mapped drive as a service, but not when run interactively

Question: I have program that reads/writes to a mapped drive.
It works properly when accessing the mapped drive if I run it interactively (e.g. double click or command line), however it fails if run as a service. (Works fine as a service if I am only accessing local drives)
There is no difference in the program code being executed in either mode, only that it cannot access mapped drives as a service.
I have tested the service running as LocalSystem, LocalService, NetworkService, and set to login as the same user account used to run it interactively, none work.
Are there additional permissions to look for? I had thought having it run as a user it would inherit all of their rights.
Environment is Wondows Server with Active Directory accounts.
Comment: Eric's answer solved the problem, however, since I can't force the mapped drives I altered the service to substitute the UNC path whenever it encounters the mapped drive path.
Answer: Not trying to be short, but i think this will answer your question.
https://stackoverflow.com/questions/182750/how-to-map-a-network-drive-to-be-used-by-a-service
See the one about using the Sys Internals tools


An example with pushout in $\mathbf{Set}$

Question: From here:

Why is in the sub-example with $Y\cap Z$, $(Y\sqcup Z)/{\sim}=Y\cup Z$? The text uses the undefined terminology ("to glue" a subset to a subset).
Also, the text claims that I an check that the square depicted is a pushout "by verifying the universal property or by using the formula just stated". What is "the formula just stated"? I don't see any formulas. As for verifying the universal property, as far as I understand, it will follow automatically from this after one verifies that $(Y+Z)/{\sim}=Y\cup Z$, right?
Answer: The 'formula just stated' refers to example 5.2.12, where it gives the general formula of a pushout in $\bf Set$.
Here we have $s:Y\cap Z\to Y$ and $t:Y\cap Z\to Z$ the inclusions, and thus the equivalence relation on $Y\sqcup Z$ is generated by $s(x) \sim t(x)$ for $x\in Y\cap Z$, that is, the $Y$-copy of $x$ is equivalent to ('glued to') the $Z$-copy of the same $x\in Y\cap Z$.
No other elements of $Y\sqcup Z$ are affected by this relation, so that their equivalence classes are singletons.
The other suggested method is to verify the universal property right away for the union $Y\cup Z$.
For that, consider two maps $Y\to W$ and $Z\to W$ which agree on $Y\cap Z$, and show they induce a unique map $Y\cup Z\to W$ (which makes the appropriate diagrams commute).
Combined with the first method, it also proves $Y\cup Z\ \cong \ Y\sqcup Z/\sim$.
Comment: Well, the unique map $\phi: Y\cup Z\to W$ is given by $\phi(t)=f_1(t)$ if $t\in Y$ and $\phi(t)=f_2(t)$ if $t\in Z$. How does this prove, together with your first paragraph, that $Y\cup Z=(Y\sqcup Z)/\sim$? And does the text suggest to prove  $Y\cup Z=(Y\sqcup Z)/\sim$ in this way?
Comment: The pushout is unique up to isomorphism in any category. By example 5.2.12, we get $Y\sqcup Z/\sim$ as a pushout. By the other method, we get $Y\cup Z$ is also a pushout. Hence they are isomorphic in $\bf Set$. And no, the text does not suggest that path to see they are in bijection with each other, it rather suggests to observe the direct identification of them.


Frequent interruptions of SSH connection to VPS

Question: My SSH sessions die at what seem like random times - response will stop, and then a few seconds later PuTTY will pop up a message with, "Server unexpectedly closed network connection."  It seems to most often happen when idle, but not always - it might even die when I'm typing in vim or something (very frustrating!).  But it's pretty frequent - if I'm very lucky it might survive for a few hours, but if I'm unlucky it might die within seconds or minutes of a login.

Server: VPS with CentOS 5.6, WebMin 1.62, OpenSSH 4.3
Client:

FTTH (or probably more accurately, to the building: 104 condos)
router #1 running NAT and security
router #2 running just as wireless access point
Windows 7 laptop (but I had the same problem with an XP desktop)
PuTTY 0.62

Most of the time I don't even use the wifi, but just connect TCP-IP (with a hub) to router #1 - but the problem remains.  I assume the fundamental cause is hiccups in my ISP's connectivity (or something in the building), but I probably can't solve that, so the reason I'm asking this on ServerFault is because I'm just trying to configure SSH (or PuTTY or whatever it takes) so that it doesn't terminate the session so easily.
I have tried various things that other people have found useful:

Setting PuTTY's Connection->"Seconds between keepalives" to various non-zero values (I don't know if that setting is like TCPKeepAlive or more like ServerAliveInterval, but it's the only setting available in PuTTY)
Trying to make the server do the work, by turning PuTTY's keepalive off (0) and then on the server, including this in sshd_config:
TCPKeepAlive no
ClientAliveInterval 60
ClientAliveCountMax 3000

Changing to a static IP for my PC (that was the solution for this question on SuperUser.com)

But it still dies in all variations - it's difficult to tell if one set of settings is slightly better than another, but each has failed even today in less than an hour.  And this problem is quite consistent over the long term - I have put up with it for the couple years I have been managing this server (I'm mostly a programmer, so I don't spend a ton of time in SSH, but when I do need it, it's frustrating to keep losing my session).  Any thoughts?
Comment: Answers should be posted as answers, not as edits to the question.
Comment: Do you have a static external IP address or is it dynamic ?
Comment: Static - it's being used as a web and mail server, etc., and I do connect using the literal IP.
Comment: I didn't think such an update would qualify as an "answer" to my original question (since the question was about the server and SSH but the solution was local), but at your suggestion, I moved it. I'm still learning the StackExchange culture, if you know what I mean.
Answer: When I have this problem, it's either due to an unstable internet connection (which in my experience is increasingly rare), or due to configuration on the server. My connections usually stay open for > 8 hours.
I'd suggest setting TCPKeepAlive to yes, since this will enforce the sshd server to be the peer that keeps the connection alive. I've never had to change anything in Putty itself.
The relevant parts of my sshd_config:
TCPKeepAlive yes
ClientAliveInterval 60
ClientAliveCountMax 3

Let me know if this helps.
Comment: From what I read, TCPKeepAlive and the ClientAlive* settings were two separate methods that the server could use to keep the connection alive, and that they shouldn't be used together (and that TCPKeepAlive was unsecured, so was the less desirable of the two).  Was I given bad info?  Anyway, I've changed the settings to what you suggested, and I'll let you know what happens.
Comment: It died with these settings also.
Comment: Disabling TCPKeepAlive is not recommended, according to the sshd_config man page, but you're right: it shouldn't have any real impact on what we're trying to accomplish here. Have you tried lowering the interval for the ClientAlive requests?
Comment: I would think that would make it worse, not better (more likely to catch the connection in hiccup mode), but I tried lowering it to 10 seconds.  No dramatic difference - my next session lasted about 15 minutes.
Comment: The Client Alive requests are there to keep the connection open (by sending requests to the client). The TCPKeepAlive directive is there to close inactive connections. So I agree that seems counter-intuitive to set it to on, but it works for me (and I have the same problem as you on default settings) and guarantees I have no ghost sessions. I know this is going to sound lame: you did restart sshd after editing these settings, right? In your case, I agree that the best bet would be to disable TCPKeepAlive (your connection appears instable), but I'm out of clues since that doesn't work either.
Comment: Don't worry, I don't mind the "lame" question, but yes, I sent SIGHUP, which has the same effect as restarting, only a bit gentler (I'm using Webmin to do the edits, Save the changes, and Apply the changes, which sends SIGHUP).  Interestingly, I had gotten the exact opposite impression of the role of the two settings - I thought TCPKeepAlive was to renew (keep alive) idle sessions by sending a null packet, and ClientAlive was to check for broken connections (client non-responsive) and close them on the server .  I wish the official docs were clearer...
Answer: The problem sorta resolved itself - I'm writing this answer to share what happened, for those who might read it later...
During the same period I had problems with my LAN-based printer throwing a "Network board error" and having to be restarted on an almost daily basis - I didn't connect the two problems because they seemed to occur at different frequencies, and because the printer driver was blaming the printer while SSH was blaming the server. When the printer errors seemed to be increasing, I decided that the machine was dying and replaced it (a several-hundred-dollar business-level color laser). But the new one had the same problem! That's when I realized that the cause was outside the printer, and started thinking it and the SSH problems (and Skype connection interruptions) might have the same cause. I tried replacing my router, to no avail. I researched some other things, but came to no conclusions. Then, after suffering with these things for a couple years, my husband replaced his PC, and all the problems suddenly went away! Apparently his PC was somehow interfering with everything on the local network, but only certain processes would show obvious symptoms, and only intermittently. My point: if someone finds this thread who has a similar problem, check the devices on your LAN, even ones that seem to work fine.
Comment: If you still have the old machine, you might boot it up on a diskless image, scan for viruses / malware.  Some malware is coded .. poorly and can flood a small network by design or by mistake.  It could also be that his pc was trying to use the gateway address for it's IP.  Or perhaps IP conflict with just the printer.  So many possibilities.
Comment: No, it's long gone. But I'm pretty sure it had no malware, as my husband tends to be paranoid and do deep scans whenever it does something unexplained. And I know it wasn't an address conflict with the gateway or any other device. Our best theory was regarding the "master browser" in windows networking - although my PC was normally the master browser, sometimes his would also try to take that role. We never figured out how to get it to behave, and we were never sure whether that was the cause of the LAN hiccups.


The (most probable) color of the card in the box

Question:
There are an equal number of red, yellow, green, and blue cards. Take one of them and put it in the box. Suppose that red cards was most selected, followed by yellow, green, and blue when we selected cards outside the box randomly. What is the color of the card in the box?$^1$

This is the problem suggested in the lecture$^2$ yesterday, and I tried to solve the problem by this way:

Formally(?) Edited Problem There are $n$ red cards, $n$ yellow cards, $n$ green cards, and $n$ blue cards. First, take one of them and put it in the box. Second, take any number of cards among the rest and examine their color. After the second step, we found that $n_r \ge n_y \ge n_g \ge n_b$, where $n_r, n_y,n_g,n_b$ is the number of (red, yellow, green, blue) cards taken in second step. What is the most probable color of the card in the box?

Attempted Solution
Let $n$ be the number of each red, yellow, green, and blue cards. Let $A$ be the event that red cards are most selected, followed by yellow, green, and blue when we get cards randomly. $R$ the event that the red card is in the box, $Y$ that the yellow card is in the box, $G$ green, and $B$ blue. Then the probability that the color of the card in the box is red, yellow, green, and blue each is $P(R|A)$, $P(Y|A)$, $P(G|A)$, and $P(B|A)$. Now let's find $P(R|A)$. By the law of total probability,
$$
P(R|A)=\frac{P(R\cap A)}{P(A)}=\frac{P(A|R)P(R)}{P(A|R)P(R)+P(A|Y)P(Y)+P(A|G)P(G)+P(A|B)P(B)}.
$$
When the red card is in the box, there are $n-1$ red card, and $n$ yellow, green, and blue card each outside the box. Then there are $\binom{n+3}{4}$ ways to select red card most, followed by yellow, green, and blue cards among total $n(n+1)^3$ ways; $\binom{n+3}{4}$ is the number of the way of choosing four elements among $0,1,\dots,n-1$ with repitition. Thus,
$$
P(A|R)=\frac{\binom{n+3}{4}}{n(n+1)^3}.
$$
Now find $P(A|Y)$. When the yellow card is in the box, there are $n-1$ yellow card, and $n$ red, green, and blue card each outside the box. We select either $n$ red cards or less than $n$ red cards. When we select $n$ red cards, there are $\binom{n+2}{3}$ ways, and when we select less than $n$ red cards, there are $\binom{n+3}{4}$ ways among $n(n+1)^3$ ways. Thus,
$$
P(A|Y)=\frac{\binom{n+3}{4}+\binom{n+2}{3}}{n(n+1)^3}.
$$
In similar way, we can find that
$$
P(A|G)=\frac{\binom{n+3}{4}+\binom{n+2}{3}+\binom{n+1}{2}}{n(n+1)^3},\qquad P(A|B)=\frac{\binom{n+3}{4}+\binom{n+2}{3}+\binom{n+1}{2}+\binom{n}{1}}{n(n+1)^3}.
$$
Since $P(R)=P(Y)=P(G)=P(B)=\frac{1}{4}$, we get
\begin{align}
P(R|A)&=\frac{\binom{n+3}{4}}{4\binom{n+3}{4}+3\binom{n+2}{3}+2\binom{n+1}{2}+\binom{n}{1}}\\
P(Y|A)&=\frac{\binom{n+3}{4}+\binom{n+2}{3}}{4\binom{n+3}{4}+3\binom{n+2}{3}+2\binom{n+1}{2}+\binom{n}{1}}\\
P(G|A)&=\frac{\binom{n+3}{4}+\binom{n+2}{3}+\binom{n+1}{2}}{4\binom{n+3}{4}+3\binom{n+2}{3}+2\binom{n+1}{2}+\binom{n}{1}}\\
P(B|A)&=\frac{\binom{n+3}{4}+\binom{n+2}{3}+\binom{n+1}{2}+\binom{n}{1}}{4\binom{n+3}{4}+3\binom{n+2}{3}+2\binom{n+1}{2}+\binom{n}{1}}.
\end{align}
Since $P(R|A)<P(Y|A)<P(G|A)<P(B|A)$, the most probable color of the card in the box is blue.
My question: Is my attempted solution correct? What is an alternative solution of the problem?

$^1$ I interpreted this question as "Find the most probable color of the card in the box."
$^2$ The lecture is not about math, but math education.
Comment: I'm confused about the (initial) question. At best this is a super poorly phrased question (ignoring the stilted english). I would interpret it as saying that in random trials red was selected most often etc. And so the color of the card in the box is is red (assuming the random trials had any bearing on the card placed in the box which seems doubtful). I completely don't understand what you are trying to do in your solution though. What are you conditioning on? More importantly what is your probability space? I can't come up with one that would make sense.
Comment: Ahh didn't intend to slight your english skills sorry about that, but the precise wording for probability questions is quite necessary. The first two steps I get, and I'm starting to see the point of the question. Essentially after choosing one card without replacement you than know something about probabilities of drawing more cards from the reduced set. I'm still not convinced the wording makes much sense and I'm strongly convinced that informal problems in probability are a VERY bad idea.
Comment: @DRF The original problem is not in English, and I am not a native speaker of English. So I attempted to translate it into English, but maybe the result was not good. The original problem was informal, so I tried to do not use variables during translation. If the use of variables were allowed, then there could be the more appropriate translation. The process is of the following:

1. There are $n$ red, $n$ yellow, $n$ green, and $n$ blue cards.
2. Among $4n$ cards, randomly select one card and put it in the box.
3. Among $4n-1$ cards outside the box, get any number of cards in one attempt.
Comment: @DRF Let $n_r,n_y,n_g,n_b$ be the number of selected (red, yellow, green, blue) cards in third step, then the condition is $n_r \ge n_y \ge n_g \ge n_b$.
Comment: @DRF I added the *variables*-added version of the problem. Could you check it?
Comment: I don't follow your argument; why are you choosing 4 elements out of $\{0,\dots, n-1\}$ with repetition? Are we not given the actual values of $n_r$, etc, only told how they compare to each other? But if that's what you are doing - including all the possibilities, then shouldn't we account for the fact that they are **not** all equally likely? That is, if we have 5 of each in the beginning, and the hidden one is red, then finding $(4, 1, 1, 0)$ is very much less likely then, say, $(2, 2, 1, 1)$
Answer: With your formal statement of the problem, it is really very simple: the cards don't care in what order the steps happen - each is equally likely to end up picked in any particular single draw. So if you imagined first having picked the $n_i$ cards for $i = r, g, b, y$ (the second step) then what is left in the pile is $n-n_i$ for each colour. So the probability that the card in the box is color $i$ is $$P(i) = \frac{n-n_i}{4n - \sum_i n_i}.$$
You can generalize to any initial numbers in the pile, not necessarily the same for each color: you will get something very similar $$P(i) = {n_{i,0} - n_i\over n_{t}-\sum_i n_i},$$
where $n_t = \sum_i n_{i,0}$ is the total number of cards in the beginning.

EDIT: I was assuming at first that the numbers $n_i$ were actually known, but when looking through your attempted solution, I'm now guessing that what you want is a probability conditional only on the event that $n_r \geq n_y \geq n_g \geq n_b$. I can adapt my argument for that purpose though.
Let's wrap all the information about the values of the $n_i$'s in some variable $N$ (it is an ordered quadruple). Let $\cal N$ be the set of all values of $N$ for which the inequality is true, and consider a particular outcome where the $n_i$'s have values that satisfy it, that is $N \in \cal N$. What I have found above then is $P(i|N)$. We don't need to bother finding $P(N)$, because we can claim from the formula for $P(i|N)$ that for every $N \in \cal N$,
$$ P(b|N) \geq P(g|N) \geq P(y|N) \geq P(r|N) $$
and at least for $n \geq 2$, for each of the inequalities above there is at least one case in which it is strict; for example, for the middle one, that would be $(1, 1, 0, 0)$. So now we have
$$ P(b\cap N\in{\cal N}) = \sum_{N\in \cal N}P(N)P(b|N) > \sum_{N\in \cal N}P(N)P(g|N) = P(g\cap N\in\cal N) $$
and similarly for the others. Dividing by $P(N\in\cal N)$, which is the same for all of them, we find $P(b|N\in{\cal N}) > P(g|N\in{\cal N}) > P(y|N\in{\cal N}) > P(r|N\in{\cal N})$.


If $X$ and $Y$ are independent random variables, is $\mathbb{E}(f(X)\mid X\le Y)=\mathbb{E}(f(X))$?

Question: This could be a stupid question, but here goes.

If $X$ and $Y$ are independent random variables, is $\mathbb{E}(f(X)\mid X\le Y)=\mathbb{E}(f(X))$?

The answer depends on the sigma algebras generated by the event $X\le Y$ and I do not think they are independent of $X$.
Comment: Of course not--take for example Y constant.
Answer: Hint: No.
Take $Y=0$, $f$ identity function, and $X$ discrete with $P(X=-1) = 0.3$ and $P(X=1)=0.7$. Note that:
$$E\left[X \; \mid \; X\leq 0\right] = \frac{E\left[X1_{X\leq 0}\right] }{P(X\leq 0)}
$$
Answer: I am not sure whether you are looking for this kind of answer or not, but here it is.
For simplicity,I will consider discrete random variables.
Let $B:=\left\{\omega:X(\omega)\leq Y(\omega)   \right\}$ and $A_x:=\left\{\omega:X(\omega)=x  \right\}$.
Left-hand side is,
$$
\mathbb{E}(f(X)\mid B)=\sum_{x}f(x)P(X=x\mid B)=\sum_x f(x) P(A_x\cap B),
$$
and right-hand side is ,
$$
\mathbb{E}(f(X))=\sum_xf(x) P(X=x)=\sum_xf(x)P(A_x).
$$
So, your claim is true so long as $A_x\subset B$ for all $x$
Comment: ...You mean, as long as $A_x\subset B$ *for every* $x$, right? That is, if $P(X\leqslant Y)=1$. That is, if there is no conditioning. :-)
Comment: @Did Indeed, thanks for pointing that out.


Saving the state of a viewpager using views as pages and not fragments

Question: I have a viewpager that uses custom views and not fragments as pages.
this custom view is basically a linearlayout with an imageview since am using my viewpager to show images.
However when screen orientation changes, everything disappears. including my imageviews. i have done research and

Most tutorials are showing how to do this with fragments.(in my case am not using fragments) Android: Saving Fragment state in ViewPager?

My viewpager adapter is using an arraylist which contain path to image files.
Below is my viewpager's adapter.(NOTE:am using an arraylist where am adding items to it and then callingnotifyDataSetChanged)
Below is my viewpager's adapter class
 public class ViewPagerAdapter extends PagerAdapter {

private Context context;
private LayoutInflater inflater;
private ArrayList<ImagePaths> imagesArray;

public  ViewPagerAdapter(Context context,ArrayList<ImagePaths> array, ){
    this.context = context;
    inflater =LayoutInflater.from(context);
    imagesArray = array;
}

public int getCount(){
    return imagesArray.size();
}

public boolean isViewFromObject(View view,Object object){
    return view == object;
}

public Object instantiateItem(ViewGroup viewGroup, int position){
    View view = inflater.inflate(R.layout.photo_layout, viewGroup, false);
    ImageView imageView =(ImageView) view.findViewById(R.id.photoView);

    final String imagePath = imagesArray.get(position);

    ImageLoader.getInstance().displayImage(imagePath, imageView);

    viewGroup.addView(view);
    return view;
}

public void destroyItem(ViewGroup container, int position, Object object){
    container.removeView((LinearLayout) object);
}
}

What do i need to do to save the state of my viewpager?
Answer: I was able to restore the state of my viewpager including it's current page when screen orientation changed by saving my arraylist and current position in
onSaveInstanceState method. later on i get the arraylist and position from the bundle in method onCreate(Bundle savedInstanceState)
public class myActivity extends AppCompactActivity{

  private ArrayList<ImagePaths> listviewArray;
  private int savedImagePosition;

  @Override
protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_layout);

    if(savedInstanceState != null){
        listviewArray = savedInstanceState.getParcelableArrayList("image_array");
        savedImagePosition = savedInstanceState.getInt("savedImagePosition");

    }else{
        listviewArray = new ArrayList<>();
        savedImagePosition =0;
    }

    ViewPager viewpager = (ViewPager) findViewById(R.id.viewpager);

    ViewPagerAdapter adapter = new ViewPagerAdapter(this,listviewArray);

    viewpager.setAdapter(adapter);
    viewpager.setCurrentItem(savedImagePosition,true);
  }

 @Override
protected void onSaveInstanceState(Bundle outState){
    super.onSaveInstanceState(outState);
    outState.putParcelableArrayList("image_array", listviewArray);
    outState.putInt("savedImagePosition",savedImagePosition);

}

}

my viewpager adapter
public class ViewPagerAdapter extends PagerAdapter {

private Context context;
private LayoutInflater inflater;
private ArrayList<ImagePaths> imagesArray;

public  ViewPagerAdapter(Context context,ArrayList<ImagePaths> array, ){
    this.context = context;
    inflater =LayoutInflater.from(context);
    imagesArray = array;
}

public int getCount(){
    return imagesArray.size();
}

public boolean isViewFromObject(View view,Object object){
    return view == object;
}

public Object instantiateItem(ViewGroup viewGroup, int position){
    View view = inflater.inflate(R.layout.photo_layout, viewGroup, false);
    ImageView imageView =(ImageView) view.findViewById(R.id.photoView);

    final String imagePath = imagesArray.get(position);

    ImageLoader.getInstance().displayImage(imagePath, imageView);

    viewGroup.addView(view);
    return view;
}

public void destroyItem(ViewGroup container, int position, Object object){
    container.removeView((LinearLayout) object);
}
}


What is the difference between the limit of a sequence and a limit point of a set?

Question: I always thought they were the same thing. The limit of a sequence is a point such that every neighborhood around it contains infinitely many terms of the sequence. The limit point of a set is a point such that every neighborhood around it contains infinitely many points of the set. So is the limit of a sequence also a limit point of a set that contains it? what's the difference?
Comment: A set can have many limit points, whereas a convergent sequence has only one limit.
Answer: Let's work in the real line, for concreteness. Consider a sequence $(x_n)_{n \geq 1}$. A limit point of the sequence is a limit point of the set $\{x_n \mid n\geq 1\}$. When you say the limit point, it means that the set $\{x_n \mid n\geq 1\}$ has only one limit point, say, $L$. And this $L$ is the element who satisfies the definition we all know and love: $$\forall \ \epsilon > 0, \ \exists \ n_0 \geq 1, {\rm s.t.} \ n > n_0 \implies |x_n - L| < \epsilon.$$
If the set $\{x_n \mid n\geq 1\}$ has more than one limit point, then the sequence $(x_n)_{n \geq 1}$ does not converge.
Comment: A limit point of a sequence $(x_n)_{n\geqslant1},$ convergent or not, need not be a limit point of the set $\{x_n\colon n\geqslant1\}.$ What is true without exception is that a limit point of a sequence is a point that either occurs infinitely often in the sequence or is a limit point of the set of points in the sequence. Or so I recently argued [here](https://math.stackexchange.com/q/3630927), but my answer to that question seems to have gone down like a lead balloon, so perhaps I slipped up? (Excuse the late comment, but this question has just been brought to the front page by a new answer.)
Comment: A limit point of a sequence does not necessarily mean it is the limit point of the range set. e.g. $ (-1)^n$ has limit points $1, -1$ but the range set $ {1,-1}$ has no limit points. The converse however, is always true.
Comment: What you can always say is: $p_n \in A \ \forall \ n \implies p \in \overline{A}$ (closure).
Comment: I guess I didn't ask the question very well. What I meant is,if pn is a sequence of some subset A of a metric space X, is the limit of pn (denoted p) also a limit point of A?
Comment: basically is the limit of a sequence also a limit point of the set that it is a part of
Comment: No. Take a metric space with the discrete metric. The only convergent sequences are constant ones (from some $n$ onward). Then, for example, take $X = \{1,2\}$ with the discrete metric. Consider $A = \{2\}$ and $p_n = 2$ for all $n$. Then $p = 2 \in A$, but it's not a limit point of $A$.
Comment: oh okay. thanks so much!
Comment: @Ivo Terek, your example works because with the discrete metric any point is isolated, specificcaly the point 2 is isolated and on the other hand your sequence $p_n$ is constant. I think that the idea of user1961722 is correct, it just need some additional condition, I mean if $p_n$ converges to p and $p_n$ is in $A$ then  $p$ is a limit point of $A$ provided that the sequence $p_n$ is not constant!
Comment: I could take the sequence $(1,2, 1,2,1,2,2, 2, 2, 2,\ldots)$ and have the same conclusion. Not *eventually* constant. But yes, I agree, with some extra conditions it should be true
Comment: I don't want to downvote the answer. I'd much rather the error was corrected. Do you dispute the accuracy of the comment I left six weeks ago? I'll happily delete it (and this one) if it's mistaken.
Comment: A sequence and the set of values of the sequence are not the same! @FariqChand's comment can be taken as an example.
Answer: In a general metric space X, it depends on the range of the sequence whether both the notions are same or not. Let $x_n$ be a convergent sequence i.e. its limit exists and is unique, say $x$. Then its range is a set, say E $\subseteq$ X, which contains all the distinct elements in the sequence $x_n$.
If the set E is finite, then it is obvious that one of the terms in E, suppose $y$, occurs infinitely many times in the sequence $x_n$. Then the limit of the sequence is, of course, $y$. Also, the $y$ is unique since the sequence is convergent so every subsequence has same subsequential limit. So, $y = x$.  But note that E has no limit point since it is finite (a point is a limit point of a subset of a metric space if all of its neighbourhoods contain infinitely many points of the subset) and in particular, all of its points are isolated points.
Now if the range set E is countably infinite (it can't be uncountable since the sequence itself is countable), then E has a unique limit point equal to $x$. Hence, every neighbourhood has infinitely many points of E and hence of $x_n$. Then for a given $\varepsilon \gt 0,$ $$\exists N \in \Bbb N \ni d(x_n,x)\lt \varepsilon\quad \forall\;n \ge N$$ Limit point is unique because if it was not the case, then there would be another point say $z\, (\neq x)$ in $\overline{E}$ which has the above property. Hence the limit of the sequence would not be unique. Thus, if the sequence $x_n$ has infinitely distinct elements, then both the notions are same.
P.S: If you consider a subset A such that A $\supseteq$ E, then as commented by littleO, A can have many limit points, different from the limit of the sequence, no matter whether E is finite or infinite. But for this case, the question of differentiating between the two notions also becomes irrelevant.
Answer: Let's take elements of a sequence as a set say S. S has many subsets, which form many subsequences of the primary sequence.
S has a limit that would be the limit of sequence & some of it's subsets too have limits those would be the limits of their respective subsequences & the limit point of whole sequence
Can say that the set of all limits of subsets would be limit points of the sequence.
Comment: Welcome to MSE. Please read this text about [how to ask a good question](https://math.meta.stackexchange.com/questions/9959/how-to-ask-a-good-question).


Approximating object statistics with Django

Question: If I had say 70,000 objects and wanted to do statistics on them, but the statistics didnt need to be 100% accurate, what is the best way to pull out say 1,000 objects, do statistics on those objects and then just scale it to approximate the statistics for the 70,000? I can't quite seem to find an efficient way to get 1000 random objects from a queryset.
Answer: You can get random objects with:
objs = list(MyModel.objects().order_by("?")[:1000])

But the underlying order by random that gets generated for the SQL isn't particularly efficient.
Comment: That is exactly what I ran into. The documentation I have read said that .order_by('?') is slow, which doesnt help if I am trying to speed things up by taking a sample set.
Answer: I know this isn't the answer you're looking for, but sometimes when doing heavy reporting you need more than Django's ORM can offer. I worked with a guy who used Django for his main application, but for some reporting tools (and a JSON service) he used Flask and SQLAlchemy and was able to accomplish a whole lot more and without having to write SQL.
Answer: there is a great post on the issue of getting random rows from the database (there are few good points in the comments too).
the only thing I would check is to get some objects by "in_bulk" method, because you may be even faster this way.


Akaike Information Criterion and composite variables

Question: Akaike information criterion is a measure for goodness of fit of a model that compensates for the number of parameters that were used to build that model.
Consider two linear models, one that is built using person's weight ($w$) and height ($h$): $f_1 = a w + b h + c$. Obviously, this model contains two parameters: w and h. Now, consider a model that uses body mass index (BMI), which is calculated as a combination of weight and height: $f_2 = aB + b$ (here, $B$ stands for BMI). Should BMI in this case be treated as a single parameter vis-a-vis AIC or as two parameters?
What about other complex model parameters that may include non-linear combination of different basic ones?
Answer: I would change "Akaike information criterion is a measure for goodness of fit of a model that compensates for the number of parameters that were used to build that model." into "Akaike information criterion is a measure for goodness-of-fit of a model that compensates for the number of parameters that need to be estimated." The larger the number of parameters, the more AIC penalises the goodness-of-fit.
In your example, BMI requires both height and weight, but only one parameter has to be estimated. Hence, if models $f_1$ and $f_2$ equally fit your data, then  according to the Akaike information criteria $f_2$ is preferred to $f_1$. (However, model $f_1$ might be more appropriate to investigate the impact of height and weight individually.)
Comment: +1  BMI forces a *very specific* and theoretically-driven relationship between height and weight.  $y=\beta_0+\beta_1*height+\beta_2*weight$ is way more flexible (e.g., able to spuriously fit unrelated data) than $y=\beta_0+\beta_1*BMI$.  That is, there is a good reason for wanting to penalize the former more than the latter.
Comment: Your answer is entirely correct.  However, I would also note that the reason why we want to penalize the number of parameters to be estimated is because the number of parameters directly relates to the variance of the estimator.  That is why penalized regression methods have lower d.f.'s than non-penalized methods when the same number of parameters are to be estimated.
Answer: Strictly speaking, you cannot compare the models as they are not nested.
But you could build a new model
$f_3 = aw + bh +cB + \epsilon$
at which points the AIC allows you to compare subsets, trading off parsimonious representation against better fit from including more variables.  In a nested model like this, you can even formally test using the $J$-test (included e.g. in R's lmtest package, as well as other commercial regression software).
Answer: I enjoyed both @ocram's and @Dirk's answers. I think a part of this question is about data reduction. Weight and height probably exhibit collinearity and can by such logic be combined into one variable.
Frank Harrell suggests in his "Regression Modeling Strategies" that one can use varclus (SAS or R) to examine the variables:
<code>vc <- varclus(~height + weight + other tested variables, sim='hoeffding')
plot(vc, legend=T)
</code>
This gives a plot that might help the evaluation of collinearity. Harrell provides an example where he looks at systolic and diastolic blood pressure. He combines these two into one variable using the mean blood pressure. There are a few chapters where he talks about variable transformation and clustering with various methods but I think the best is when you have a natural transformation such as the weight + height --> BMI.
You usually have to reduce the parameters to minimize the shrinkage before going into testing. The AIC method is very dependent on the degree of shrinkage, it can be estimated from $\frac{LR-p}{LR}$ where LR is the log likelihood ration $\chi^2$ and p the number of parameters in the model. The aim is to keep shrinkage above 0.9. In a binary logistic model a rule of thumb is a 10:1 ratio for number of events to degrees of freedom.
I'm still working my way through Harrell's book but I hope I got the basics right. Please comment if something seems a little off.


Issue Installing java

Question: so i was installing java and my pc decided to shut off before it could finish, i don't have java anymore, and now when i try to open the installer it never opens, i have tried using CCleaner to clean the registry, i have tried installing in safe mode, someone told me to check the checksum to make sure the file isn't corrupted and its not, i have tried the offline and online installers with no luck
i have been trying to solve this for a week with no luck =P was hoping you guys could help
Comment: While this is on topic here at SO, you may get better responses over at http://www.superuser.com
Comment: What version of Java were you trying install, and was this the JRE or the JDK?
Comment: i was trying to install jre 8U91 the one available right from http://java.com/en/download/
Answer: You could try deleting the location it was installing to and then reinstalling.

Issue Installing java


New dataframe of all non-NaN pairs of elements between two columns in pandas

Question: Trying to go from a DataFrame where each row is a source entity and columns are the type of relations between one or more entities like this:
import numpy as np
import pandas as pd

i = [['a', np.nan, np.nan, ['d', 'e']],
     ['b', 'f', np.nan, np.nan],
     ['c', np.nan, 'g', 'h']]
inputs = pd.DataFrame(i, columns=['source', 'mom', 'dad', 'sibling'])

To one where each row includes a source's unique target entity and relation type in separate columns:
o = [['a', 'd', 'sibling'],
     ['a', 'e', 'sibling'],
     ['b', 'f', 'mom'],
     ['c', 'g', 'dad'],
     ['c', 'h', 'sib']]
outputs = pd.DataFrame(o)

I've looked at pandas functionality including stack() and explode() but can't figure out how to implement a pandas-native solution. Any suggestions on how to do this efficiently?
Comment: ``inputs.explode('sibling').melt('source').dropna()``
Comment: So I think if I chain explode after melt, I should be good to go: inputs.melt('source',var_name="relationship").dropna().explode('value')
Comment: Ah, melt was the thing I needed. Is there any way to account for when the lists are uneven? I'm trying to inputs.explode(['mom','dad',''sibling']) but this won't work because some of the lists are not all of the same length. Thanks @sammywemmy!
Comment: that will be tricky. you are better off working within python before going back to Pandas. see if the solution [here](https://stackoverflow.com/a/69795129/7175713) helps
Comment: you can post your solution, and mark it as well. It will be helpful to me and others
Answer: Per @sammywemmy , melt and explode should do the trick:
inputs.melt("source", var_name="relationship").dropna().explode('value')


Why would you need merely the term "collection" for pitches, but not "scale"?

Question: In his lecture Understanding the Fundamentals of Music from 2006, Robert Greenberg says (on p. 119 of the transcript) this quote. Scan of that page is at the bottom.

Despite its overwhelmingly common usage, the word scale is, from a conceptual point of view, used incorrectly a good 99% of the time. The word scale is derived from the Latin word for ladder. So, when we say "C-major scale," what is implied is a stepwise ordering of pitches, climbing up or climbing down. The world scale, therefore, cannot properly be used to address a group or set of pitches in which no ordering is implied. That's where the word collection comes in. By using the word, collection, no step-wise ordering is implied. Instead, the word collection addresses a group of pitches arrayed around a single, tonal center (or tonic) pitch. Thus, a C-major collection means a collection of pitches in the major mode, arrayed around the pitch C. Now, I know this might sound like terminological nit-picking, but by using the proper terminology, explanations, conceptualization, and comprehension will be much easier as we progress through our examination of pitch. Trust me on this, please.

I still don't understand when you need collection but not scale. In what contexts would you need to discuss pitches without step-wise ordering?
Please quote only reputable musicologists and music textbooks. Are there examples from them where "scale" was misused and ought be replaced by "collection"?
Comment: Lolz for "trust me on this, please". Clearly it's been a point of discussion in the author's life! :)
Comment: This is merely a concept developed by the author of the quoted passage, and the passage itself explains the concept. And I've never heard anyone use the word "collection" in this sense. The whole idea seems overly pedantic to me. In any case, most likely there is no further explanation possible for this strange idea beyond the one you've already got.
Comment: Please don't post text as an image; it can't be searched, copy/pasted into answers or read by screen-readers for the visually impaired.
Comment: @ToddWilcox : I think «pitch class set» exists https://en.m.wikipedia.org/wiki/Set_theory_(music) I agree though... Looks like an exercise in pedantry
Comment: Robert Greenberg is wrong by claiming that "scale" is used incorrectly a good 99% of the time. I don't think I have ever met a musician who was not aware that a scale is a stepwise order of notes. If someone says a piece of music is built on the C-major scale he simply means that the notes in the C-major scale is the base for that music. He does NOT say that the music is a scale. He is of course aware that a scale is a stepwise order of notes, he just points out what the music is built upon. It is easy to understand in my opinion, no reason to complicate matters with the term "collection".
Comment: To be fair a somewhat analogous concept pair to (collection, scale) is fundamental in Indian music. N India it's (thaat, raga). https://en.m.wikipedia.org/wiki/Thaat . S India it's (melakarta, janya) https://en.m.wikipedia.org/wiki/Melakarta
Answer: Sometimes it's easiest to see concrete musical examples.
The author's claim here is that a scale is only the stepwise ordering (hence "ladder") like that shown in the following:

Contrast this with the following Debussy excerpt:

In this latter excerpt, there is no stepwise pattern, so the author is making the claim that it's incorrect for us to say "this excerpt uses the C-major scale." Instead, we should be clear that there is no scale here and say instead that "this excerpt uses the C-major collection" (or C Ionian, but that's a discussion for another time).
In my experience, the distinction between "scale" and "collection" mainly becomes important when dealing with twentieth-century (and beyond) techniques like modes. We would never say that "the C-major scale is the same as the E-Phrygian scale," but we can say that "the C-major collection is the same as the E-Phrygian collection." It's a bit like the square and rectangle issue: a scale is a collection, but a collection isn't necessarily a scale.
(Oh, and as for your request to quote only reputable musicologists: does having a PhD in music theory count?)
Comment: The idea that [mode](https://en.wikipedia.org/wiki/Mode_(music)) is a twentieth-century concept is baffling.
Comment: @phoog You're right, of course. I may have been unclear; I meant that mode is a concept used in the twentieth century, not that it stems from that time.
Answer: So I like Richard's Answer, and I think it's good, but I think it's worth adding as an addendum that his definition of "collection" actually disagrees with the author's.  The author says :

The world scale, therefore, cannot properly be used to address a group or set of pitches in which no ordering is implied. That's where the word collection comes in. By using the word, collection, no step-wise ordering is implied. Instead, the word collection addresses a group of pitches arrayed around a single, tonal center (or tonic) pitch. Thus, a C-major collection means a collection of pitches in the major mode, arrayed around the pitch C.

Now, leaving aside that the author in the quest for terminological precision has used the very vague and difficult to define term "arrayed around" , the author clearly feels that "C major pitch collection" should denote the set of notes of the C major scale, with the tonic of C, but not necessarily arranged in the step-wise order of a "scale"
In this sense, it would be incorrect to describe the melody of Happy Birthday (below) a "using the C major scale" because there is no "scale proper" "true scale" (to coin new terms for an explicit, step-wise scale) in the melody.  This would mean that it would only be correct to describe it as using the "C major collection".
X: 1
T: Happy Birthday
M: 3/4
L: 1/4
R:
K: Cmaj
|G3/4G1/4|A G c | B2 G3/4G1/4|A G d |c2 G3/4G1/4|
|g e c | B A  f3/4f1/4|e c d | c2

According to the author's definitions, it would be incorrect to refer to Scarborough fair as using the "C major pitch collection" though, as it is centred around the "D dorian pitch collection"
X: 2
T: Scarborough Fair
M: 3/4
L: 1/4
R:
K: D dorian
|D2 D | A A A | E3/2 F1/2 E | D3 | z A c | d2 c | A B G | A3 |
| z2 d | d2 d | c2 A | A G F | (E1/2C1/2-C2) | z4 | D2 A | G2 F | E D C | (C1/2D1/2-D2)

However, Richard makes the following point:

In my experience, the distinction between "scale" and "collection" mainly becomes important when dealing with twentieth-century (and beyond) techniques like modes. We would never say that "the C-major scale is the same as the E-Phrygian scale," but we can say that "the C-major collection is the same as the E-Phrygian collection." It's a bit like the square and rectangle issue: a scale is a collection, but a collection isn't necessarily a scale.

This means that, according to Richard, it could be perfectly correct to describe Scarborough Fair as using the "C major pitch collection", since it uses only the notes found in that collection.
So in our quest for more precise terminology, we have ended up with a different ambiguity.  We've resolved the ambiguity of the word scale meaning both:

1) a set of notes played sequentially in a stepwise motion
and
  2) a restricted set of notes, with a tonic, used to construct a piece of tonal music

but introduced our own definitional ambiguity for "collection" of:

1) a restricted set of notes, with a tonic, used to construct a piece of tonal music
vs.
  2) a well defined set of notes, in any order, in any musical context

And in addition to this new ambiguity, I don't think the original ambiguity for the word "scale" actually causes problems, because it's clear from context whether we're talking about an "actual" sequential scale being played in a piece of music, vs "the scale" as a set of notes used to construct music.
Much like the word "alphabet" might mean "the set of letters used to write a language" and it could also mean "ABCDEFGHI..." in order, the difference between "English uses the Latin Alphabet" vs. "He wrote out the English alphabet" is clear from context, as is:

"the flutes in this passage play rapid C major scales"
vs.
  "this melody uses the C major scale"

If disambiguation is really required you could say you could substitute scales and scale respectively for "stepwise C major scales" or "the notes of the C major scale", but imo neither is required in either of my (relatively typical) examples.

In conclusion, to borrow the verbage of to the author:
Now, I know this might sound like terminological nit-picking, but, for these reasons, I'll keep using "scale" for both of its conventional definitions. Trust me on this ;)
Answer: To my mind, the word "scale" does have two distinct common usages; when analysing the tonality of a piece of music, it often does mean 'collection' insofar as order in time is not a primary consideration; On the other hand, there is also the pedagogical form of the scale which presents the collection of pitches ascending or descending in time order (i.e. what you'd play if asked to present the scale in a music exam).
However, I think the author here goes a little far when he says:

The word scale... cannot properly be used to address a group or set of pitches in which no ordering is implied.

The word pitch itself refers to the sensation of frequency, which by most standards is an entirely objective, measurable concept. Any group of distinct defined pitches has an inherent order corresponding to the frequency values; In this sense, even the 'non-pedagogical' usage of scale still refers to something that has an order.
The appeal to Latin also seems a little over-wrought. Can the author objectively establish that the importance of the meaning of "scala" is climbing? I always considered that the important aspect of the analogy was that the "rungs" were at defined points in pitch space, corresponding to the notes defined to be in the scale (just as the rungs on a ladder are at set heights).

please quote only reputable musicologists and music textbooks.

In this very book, the author concedes that the "overwhelmingly common usage" of scale is to refer to collections of pitches that are not ordered in time. He characterises this usage as "incorrect", but as discussed above, his argument seems specious.
Of course there is still a conceptual difference between the idea of a set of pitches separated in time with time corelating to pitch, and a set of pitches not separated in that way - and It would seem perfectly reasonable for an author to say that they will use "scale" for the first concept, and "collection" for the second. But it's not necessarily reasonable to say that the common usage of "scale" for the second concept is incorrect.
Answer: I never encountered the idea that - in English - scale means exclusively the tones all in step-wise order... except on this StackExchange forum! That singular meaning of scale has always struck me as strange.
Obviously, specifying the tones in step-wise order construes a performance aspect. Supposedly we could only refer to a scale when we have a step-wise execution of tones. That's a very concrete meaning.
But, the sequence of tones isn't the important aspect of defining a scale. The important thing about a scale is defining the tonic. For example, the C major scale is defined by C being the tonic regardless of the order the tones.
I think the clearest proof of the point is the term scale degree. Scale degrees are referred to with no concern for the order of tones. The degrees are obviously identities in a collection of tones related to a tonic. That is an abstract idea. It's common to refer to a scale abstractly and not necessarily meaning a step-wise sequence.

Please quote only reputable musicologists and music textbooks. Are there examples from them where "scale" was misused and ought be replaced by "collection"?

I think the problem is going to be a definition versus usage.
Consider these examples from Kostka/Payne's Tonal Harmony...
A definition:

...just about any definition of scale will include various wordings about tonleiter or
 conjunct motion.
Usage of term scale where there isn't a tonleiter:

...the author's could have used a wording like "^1 of the Eb major collection", but they didn't. Not because they are misusing the term, but because it isn't necessary.

...the word scale is, from a conceptual point of view, used incorrectly a good 99% of the time

It seems the author is odd one out. Kostka/Payne use scale in the general sense of tone collection and many others do the same.
Personally, I don't have any problem understanding the two meanings of scale from context. Examples: "I practice my scales everyday." The context is performance, they are talking about tonleiter. "This scale in sixteenth notes is merely an elaboration of a single chord." That's a concrete example of a tonleiter. "In this passage in C major the F# is chromatic and is a temporary leading tone from the G major scale." That usage means key, tone collection, tonality, etc.
If there was a deeper significance to the distinction Greenberg makes, I would be on board with him. But I just don't see it.
Comment: I guess he defines the two terms in order to be able to use one or the other when specifically talking about one of the two concepts. Of course he could have just explained that, instead of pretending it's some kind of important distinction that other people get wrong.
Comment: @YourUncleBob : That about sums up my position. Making a distinction for the purposes of clarification and elucidation is one thing. Saying everyone who doesn't is wrong is quite another
Answer: The author states that the word scale is used incorrectly 99% of the time. I find this claim to be wrong. In 99% of the time, we give functions to notes, bringing order to this collection. The vast majority of notes in compositions have two dimensions: a function (tonic, mediant, ..) and a pitch class (any semi-tone in the octave).

I still don't understand when you need collection but not scale. In
  what contexts would you need to discuss pitches without step-wise
  ordering?

In Music Set Theory, only one dimension is used - the pitch class. From this perspective, a collection rather than a scale could make sense.


How is TD(1) of TD(lambda) equivalent to Monte Carlo?

Question: In Sutton and Barto's book about RL they say that the TD($\lambda$) algorithm is equivalent to Monte Carlo when $\lambda = 1$. I don't see how that is the case.
They define the lambda return as:
$$G_t^{\lambda}=(1-\lambda)\sum_{n=1}^{\infty}\lambda^{n-1}G_{t:t+n}$$
Even at this point you can see that $\lambda=1$ means the lambda return would be zero for any t.
But let's carry on. For episodic problems, because we have a terminating time step T, the lambda return can be broken up into two parts (this is the equation they use to justify the equivalence of TD(1) and Monte Carlo):
$$G_t^{\lambda}=(1-\lambda)\sum_{n=1}^{T-t-1}\lambda^{n-1}G_{t:t+n} + \lambda^{T-t-1}G_t$$
From this last equation you can clearly see that $\lambda = 1$ results in the lambda return being the actual return i.e. Monte Carlo. But I think this equation only works for $0\le\lambda<1$ because the last equation is derived as follows:
$$G_t^{\lambda}=(1-\lambda)\sum_{n=1}^{\infty}\lambda^{n-1}G_{t:t+n}$$
$$G_t^{\lambda}=(1-\lambda)\sum_{n=1}^{T-t-1}\lambda^{n-1}G_{t:t+n}+(1-\lambda)\sum_{n=T-t}^{\infty}\lambda^{n-1}G_{t:t+n}$$
Now because every one of the returns of the second sum gets out of the bounds of the episode, we replace it by the actual return $G_t$ and we get
$$G_t^{\lambda}=(1-\lambda)\sum_{n=1}^{T-t-1}\lambda^{n-1}G_{t:t+n}+G_t(1-\lambda)\sum_{n=T-t}^{\infty}\lambda^{n-1}$$
The second sum is now an infinite geometric series with $a_1=\lambda^{T-t-1}$ and $q=\lambda$. The sum of this series is given by $S=\frac{a_1}{1-q}$. When we plug in our values we get that $S=\frac{\lambda^{T-t-1}}{1-\lambda}$. Plugging that back into the equation we get the same equation as before(which is given in the book):
$$G_t^{\lambda}=(1-\lambda)\sum_{n=1}^{T-t-1}\lambda^{n-1}G_{t:t+n} + \lambda^{T-t-1}G_t$$
But here's my problem with that argument: it only works for $0\le\lambda<1$ because the sum of an infinite series is only given by the used formula if $\mid{q}\mid \lt 1$.
Can you please tell me where am I going wrong?
Comment: In fact, your detailed "question" answered my problem, thanks a lot! Maybe I could contribute my understanding here. I think the last equation in your description is valid as long as it's episodic. It's not necessary to ask for it from the first equation. So if you directly write it with the natural meaning, then it's OK if lambda is 1.
Comment: Yeah, I mentioned in my question that the last equation is valid only for the episodic case because I derived it with the assumption that it was episodic. I don't know what you mean by the natural meaning, but the first equation is equal to 0 if lambda is 1. Anyways, I'm glad I helped you somehow :)
Answer: The last equation in your description is valid as long as it's episodic. It's not necessary to ask for it from the first equation. So if you directly write it with the natural meaning, then it's OK if lambda is 1.
By "natural meaning": the lambda return of TD(lambda) is the weighted average of future returns in each step. Then, facing an episodic case, it's "natural" to write in that way, and not necessary to derive it from other case (continuing case).


Determine the limit if it exists

Question: Given
$S = 1 + r + \frac{1}{2}r^2 + \frac{1}{3}r^3 + \cdots$
Check its convergence and determine the limit of $S$ if it exists.
My attempt:
I have checked the convergence of $S$ by using ratio test.  I found that $S$ will convergent if $r < 1$.  Now,  if $S$ is convergent, then $S$ must be has a limit, is not it? The next question is asking for the limit and I am stuck at this.  Please help,  regards.
Answer: You probably know that $\sum_{n=0}^{\infty} x^{n} = \frac{1}{1-x}$ for $|x| < 1$. Then notice
$$\frac{\mathrm{d}}{\mathrm{d}x} \left( \sum_{n=1}^{\infty} \frac{x^{n}}{n} \right) = \sum_{n=0}^{\infty} x^{n} = \frac{1}{1-x}.$$
So
$$1+\sum_{n=1}^{\infty} \frac{x^{n}}{n} = 1+\int \frac{\mathrm{d}x}{1-x} = 1- \log(1-x).$$
Comment: Why don't we have to worry about a $+c$?
Comment: I equally well could've included the integration constant by writing $1 + \sum \frac{x^{n}}{n} = 1 - \log(1-x) + C$. Then, setting $x = 0$ on both sides of the equation yields $1 = 1 + C$, so $C = 0$.
Comment: It deduces that $S$ willl convergent to $- \log(1-x)  + 1$?
Comment: You're right, I forgot about the $1$ at the beginning of your original series.
Comment: is not you change $S$ into summation form,  but you leave 1 as $S = 1 + \cdots$
Comment: Yes, you are right. I have edited my answer.
Comment: Thanks for the answer,  Mark.  I understand right now.  :)
Comment: No problem. Consider accepting my answer (by clicking the checkmark to the left) to let others know that you're question has been satisfactorily answered.
Answer: $S-1=-(-r)+\dfrac{1}{2}(-r)^{2}-\dfrac{1}{3}(-r)^{3}+\cdots=-\log(1-r)$.
Comment: though OP has not yet stated issues when $r \le -1$
Comment: which will obviously have issues if $r \ge 1$
Comment: Yes, true, but OP has noticed that.

Determine the limit if it exists


In fluid dynamics, are these terms used interchangeably?

Question: When I see a plot of a velocity vector field that describes a fluid flow, are the terms "flow field", vector field, velocity field, "velocity profile", and "flow profile" all used interchangeably?
There seem to be differences depending on whether it is a flow over time, $t$, or whether it's a snapshot of the flow, with no dependence on time.
I put quotations on the terms that I am not sure of but hear frequently in a seminar, so I just want to be sure.
Thanks,
Answer: Not all of them are equivalent.
"flow field" and "velocity field" are the representation of the "vector field" of velocities. Which means, the representation of velocity field lines through the fluid.
On the other hand, the "velocity profile" or "flow profile" is a diagram that plots the speed of the fluid against a the distance. This is usual in certain delimited channel, like a pipe, a tube, or a canal.
In sum, the first one represents the arrows of the vector field along the fluid. The second one represents the scalar magnitude of velocity in a cross section of the fluid. Some pictures might help:
1.- Velocity field lines:
http://fcm.ens.uabc.mx/~chelo/analisis%20vectorial/nucleos/capitulo2/leccion2_4/mates/ecdif/l2-4b_files/image018.jpg
2.- Velocity profile (arrows are helping, but the function that joins their tips is what matters)
http://www.bvsde.paho.org/arquitectura/clase23/barce5.gif
Comment: Thanks so much for your answer!


C# Conditional operator

Question: age < 18 ? Console.WriteLine("Too Young") : Console.WriteLine("Old enough");

I am trying to get this line of code to run but keep getting CS0201 error on visual studio. Whats wrong?
Comment: [Error CS0201](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0201)
Comment: [?: operator (C# reference)](https://learn.microsoft.com/en-US/dotnet/csharp/language-reference/operators/conditional-operator)
Comment: `WriteLine` is a `void` method. You can't use that in a conditional.
Comment: Sure. `age< 18 ? Console.WriteLine("Too Young") : Console.WriteLine("Old enough");` is also not a valid statement, regardless, as the error indicates. See @J...'s comment.
Answer: The conditional operator requires an expression. Console.WriteLine is not an expression.
But a string is an expression, so you can say:
Console.WriteLine(age< 18 ? "Too Young" : "Old enough")

Or use an if-statement.

C# Conditional operator


in iOS 5, How to use AudioSession to make sure audio is played through speaker although earphone is plugged in?

Question: <code>- (void)viewDidLoad
{
    [super viewDidLoad];

    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"1"
                                                         ofType:@"mp3"];

    // Convert the file path to a URL.
    NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath];
    [[AVAudioSession sharedInstance] setDelegate: self];

    UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
    AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);

    //Initialize the AVAudioPlayer.
    self.audioPlayer = [[AVAudioPlayer alloc]
                        initWithContentsOfURL:fileURL error:nil];
    self.audioPlayer.volume = 1.0;

    // Preloads the buffer and prepares the audio for playing.
    [self.audioPlayer prepareToPlay];

}
</code>
it's reporting run time error:
<code>Undefined symbols for architecture armv7:
  "_AudioSessionSetProperty", referenced from:
      -[SoundTesterViewController viewDidLoad] in SoundTesterViewController.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
</code>
Comment: i have the same problem,is this code working.
Answer: Be sure to include the AudioToolbox lib in xCode. I had the same error because the files were imported but did not link the library to the project.
This should get rid of the error you have.
Have a nice day!


Suppose $M$ is a closed supbspace of $L^2[0,1]$ whic his contained in $C[0,1]$, where $C[0,1]$ has a topology provided by the supremum norm.

Question: Suppose $M$ is a closed supbspace of $L^2[0,1]$ whic his contained in $C[0,1]$, where $C[0,1]$ has a topology provided by the supremum norm.
For each $x \in [0,1]$, prove that there exists a function $k_x \in M$ such that:
$f(x) = \int_0^1 \overline{k_x(y)}f(y)dy$ for all $f \in M$ where $\overline{k_x(y)}$ is the conjugate of $k_x(y)$.
The function $K(x,y)=k_x(y)$ defined on $[0,1]\times[0,1]$ is called the reproducing kernel for $M$.

So I feel like I should get the Riesz representation theorem involved but I'm struggling to figure out how exactly... I've been stuck on this problem for at least a week and the gears arn't really  turning at all.. I could really use some help on this one!! Thanks I appreciate it so much!
Answer: Hints:

By the Riesz representation theorem, it suffices to show that the evaluation functional $\pi_x : M \to \mathbb{R}$, where $\pi_x(f) = f(x)$, is continuous with respect to the $L^2$ norm on $M$.
The evaluation functional is definitely continuous on $C([0,1])$, so it would be enough to show that the inclusion map $i : M \to C([0,1])$ is continuous (where $M$ is equipped with the $L^2$ norm and $C([0,1])$ with the sup norm).
To prove that $i$ is continuous, try using the closed graph theorem.
Comment: Sorry to hijack the question, but I have a question. If $\pi_x: M \to \mathbb{C}$ where $M$ is equipped with the $L^2$ norm, then isn't this mapping not well-defined since $L^2$ consists of equivalence classes? Can't we find two continuous functions such that $f=g$ a.e.?
Comment: @zugzug: No, you can't.  (It is a good exercise to prove this; it suffices to show that every full-measure subset of $[0,1]$ is dense.)  Thus the mapping is in fact well defined.  Actually, this needs to be true for the statement "$M$ is contained in $C([0,1])$" to make sense at all.
Comment: @MSV: The Riesz representation theorem is for *continuous* (aka bounded) linear functionals on a Hilbert space.  How else do you plan to prove that the functional $f \mapsto f(x)$ is continuous?  (Or do you have in mind some other version of the theorem?  If so, please give a precise statement.)
Comment: @MSV: In case it wasn't clear, my hint is to use the closed graph theorem to prove that $i$ is continuous.
Comment: I don't understand why we need to use the closed graph theorem here. Don't we already have the representation we want of $f(x)$ just from the Riesz Representation theorem?
Comment: Ohhh thanks man.
Comment: @NateEldredge : You are right, but I'm curious where I learned incorrectly. I thought in the $L^2$ setting, when you say $M\subset C([0,1])$, you really mean if $f \in M$, then there is some $g$ such that $f=g \, a.e.$ and $g$ is the unique (true) continuous function chosen from the equivalence class. Hence, the $f\in M$ aren't really continuous, they just behave exactly like continuous functions inside the integral.
Comment: I see why it makes sense to say $f \mapsto f(x)$, where $f(x)$ is the unique continuous representative evaluated at $x$. But technically speaking, isn't there mapping between? i.e. Map $f$ to the unique continuous representative, then map that to $f(x)$? Obviously that's what's going on, but is it ever said explicitly, or does everyone just assume what I discussed without comment?
Answer: For the sake of my own review and to benefit the OP, I'm going to fill in some of the subtle details in the set up.
First of all, denote $X$ and $Y$ as the subspaces $M$ with the $\sup$ and $L^2$ norms, respectively. We know $Y$ is closed so it is a Hilbert space. The motivation is to say the linear functional $T_x:Y\to \mathbb{C}:f\mapsto f(x)$ is bounded. The existence of $k_x\in Y$ then follows from Riesz Representation.
Note that the mapping $T_x$ is well-defined since for each equivalence class of continuous functions in $L^2$, there is a unique representative that is continuous pointwise everywhere. Put differently, $T_x$ can be understood as $T_x: Y \stackrel{i_Y}\to X \to \mathbb{C}:y\mapsto y\mapsto y(x)$, where $i_Y$ is the identity mapping. The mapping $i_Y$ is well-defined by the comment above.
Obviously, we want to show $|T_x f|\leq C ||f||_2$ for all $f\in Y$. An intuitive thing to try is
$$
|T_x f|=|f(x)|\leq ||f||_\infty\leq C ||f||_2.
$$
But without more information, it's not obvious that $C$ exists.
What is clear is that by Holders,
$$
||f||_2^2=\int_0^1 |f(t)|^2 \,dt \leq |||f|^2||_\infty\, ||1||_1=||f||_\infty^2
$$
so $||f||_2 \leq ||f||_\infty$. We can show $X$ is closed; therefore, $X$ is a Banach space. Suppose $f_n \stackrel{X}\to  f$, where $f_n \in X$. Then
$$
||f_n-f||_2\leq ||f_n-f||_\infty \to 0.
$$
Hence, $f_n \stackrel{Y}\to f$. Since $Y$ is closed, we must have $f \in M$. Therefore, $f \in X$.
The open mapping theorem says that since $i_X: X \to Y: f\mapsto f$ is surjective (bijective actually) and $X$ is a Banach space, this implies $i_X$ is an open mapping. In other words, a continuous inverse $i_Y: Y \to X: f \mapsto f$ exists. By definition, there exists $C>0$ such that $||f||_\infty=||i_Y(f)||_\infty \leq C ||f||_2$.
From here, we know $T_x$ is bounded so we just apply Riesz representation theorem on the Hilbert space $Y$.
Comment: haha, I heard it was a bust. I don't play video games anymore for a variety of reasons. But I used to love warcraft 3.
Comment: nice man, your portrait inspired me to get wc3 reforged btw hahaha lmk if u ever wanna play some gamez
Comment: lol as long as its not WORSE than wc3 thats all i'm asking... it seems be to be wc3 with a bit of updated graphics,,, i'm down


$views->render() does not display node_path

Question: So I made a view and Im trying to pull the results into an array (which I am json encoding and sending to javascript but thats neither here nor there) but some of the node information isnt being pulled. Specifically the node_path.
When I preview the view in the edit views page in the backend, the path shows up. But when I pull the view on the front end from my preprocess_page function the node path is not outputted.
In my view, I'm displaying the following fields:

Node: Post Date
Node: Title
Node: Teaser
Node: Type
Node: Path

And each of these fields shows up in the preview. But when I try to pull the view using the code below the path isnt output:
<code>$blog_posts = json_encode(theme_get_view_result('front_page_blog_blocks'));

function theme_get_view_result($viewname) {
  // views_get_views_result($viewname) produces the same result as $view->result;
  // Im just showing that I tried both
 //return views_get_view_result($viewname);

  $view = views_get_view($viewname);
  if(!empty($view)){
    $view->preview();
    return $view->result;
  }else{
    return 'empty';
  }
}
</code>
what I also noticed, is that the date was output as a unix timestamp, and not the format I selected (custom, 'M j').
So the result produced in my console is:
<code>    {"nid":"1","node_created":"1312470739","node_title":"blah blah blah this is my title","node_revisions_teaser":
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce auctor vestibulum gravida. Proin ornare nisi non orci feugiat ut hendrerit mi venenatis. Etiam diam ligula, pellentesque et vehicula sed, ultrices at lorem. Vivamus consectetur risus nisl. Vivamus luctus volutpat dolor,","node_revisions_format":"2","node_type":"blog"},
</code>
So notice: there is in incorrect timestamp, and the node path is missing. Im a total Drupal noob so I have no idea whats going on.
Answer: aha! turns out render() only produces data saved in the database, and node paths are not saved in the DB. So my solution was to grab the node id from the rendered view, use that to get the node paths, and created a new field with that path like so:
<code>function theme_get_view_result($viewname) {
  // views_get_views_result($viewname) produces the same result as $view->result;
  // Im just showing that I tried both
 //return views_get_view_result($viewname);

  $view = views_get_view($viewname);
  if(!empty($view)){
    $view->preview();
    return $view->result;
  }else{
    return 'empty';
  }
}

$blocks = theme_get_view_result('front_page_blog_blocks');
foreach($blocks as $k=>$v)
{
  $node_path = drupal_lookup_path('alias','node/'.$blocks[$k]->nid);
  $blocks[$k]->node_path=$node_path;
}
</code>


Prove that if any closed ball in $X$ is compact then there exists $y\in F$ such that $d(p,y)=d(p,X)$, for $F$ closed, $p$ a point.

Question: Let $(X,d)$ be a metric space, $F$ included in $X$ and closed, p a point in $X-F$.
Prove that if any closed ball in X is compact then there exists y in F such that
$d(p,y)=d(p,F)$.
I have been trying to do it by sequences, but i dont know how to use the hypothesis.
Comment: Isn't $d(p,X)$ going to be zero? Do you mean $d(p,F)$?
Comment: Get us started by showing us your thoughts and what you have tried. Then we will likely chime in to help.
Comment: Your idea with sequences is on the right path. Basically, the distance $d(p,F)$ is the infimum over $x\in F$ of $d(p,x)$. If you know (or can see that $d(p,\cdot)$ is a continuous function, then what can you say about the infimum over a compact set (can you see that $p$ must be in some compact set?)?
Answer: Pick some $x\in F$ and let $\alpha=d(p,x)$, then we can restrict our search to $\overline{B_\alpha(p)}\cap F$ (where $B_r(a)$ is the ball of radius $r$ around $a$). This is a compact set as it is a closed subset of a compact set. Now $d(p,\cdot)$ is continuous and hence its infimum must be attained over $\overline{B_\alpha(p)}\cap F$. So there is some $y\in F$ that get us the result.
Comment: I don't think it can be - $x$ should be in $\overline{B_\alpha(p)}$ shouldn't it?
Comment: Ah meant to say $x\in F$
Comment: Yes you right. I delete my comment. This is a good proof.
Answer: You can see here
A metric space such that all closed balls are compact is complete.
that every metric space in which the balls are compact is complete.
Then construct a sequence $x_n$ in $F$ such that $d(p,x_n)-d(p,X)<\displaystyle\frac{1}{2n}$. Prove that this sequence is Cauchy.
Sorry by the mistake before!


Showing list of all 24 hours in sql server if there is no data also

Question: I have a query where I need to show 24 hour calls for each day.
But I am getting the hours which I have calls only.
My requirement is I need to get all the hours split and 0 if there are no calls.
Please suggest
Below is my code.
    select  @TrendStartDate
    ,isd.Name
            ,isd.Call_ID
            ,isd.callType
            ,DATEPART(HOUR,isd.ArrivalTime)
    from [PHONE_CALLS] ISD WITH (NOLOCK)
    WHERE CallType = 'Incoming'
    and Name not in ('DefaultQueue')
    and CAST(ArrivalTime as DATe) between @TrendStartDate and @TrendEndDate

Comment: Read Aaron Bertrand's [Bad habits : Putting NOLOCK everywhere](https://www.sentryone.com/blog/aaronbertrand/bad-habits-nolock-everywhere)
Comment: Maybe make a temp table with all numbers from 1 tot 24 in there, and then join to jour [PHONE_CALLS] table with a LEFT OUTER JOIN, so that you get every hour?
Comment: For help on generating your numbers from 0-23 for your hours the following series should help [Generate a set or sequence without loops – part 1](https://sqlperformance.com/2013/01/t-sql-queries/generate-a-set-1), [part 2](https://sqlperformance.com/2013/01/t-sql-queries/generate-a-set-2), and [part 3](https://sqlperformance.com/2013/01/t-sql-queries/generate-a-set-3).
Comment: It would be great if you could show us some sample data and desired output.. I have a partial answer, but I'm not sure if it's what you're looking for.
Comment: @RaduGheorghiu added sample and output data in main question
Answer: If you have a numbers table you can use a query like the following:
SELECT  d.Date,
        h.Hour,
        Calls = COUNT(pc.Call_ID)
FROM    (   SELECT  [Hour] = Number
            FROM    dbo.Numbers
            WHERE   Number >= 0
            AND     Number < 24
        ) AS h
        CROSS JOIN
        (   SELECT  Date = DATEADD(DAY, Number, @TrendStartDate)
            FROM    dbo.Numbers
            WHERE   Number <= DATEDIFF(DAY, @TrendStartDate, @TrendEndDate)
        ) AS d
        LEFT JOIN [PHONE_CALLS] AS pc
            ON pc.CallType = 'Incoming'
            AND pc.Name NOT IN ('DefaultQueue')
            AND CAST(pc.ArrivalTime AS DATE) = d.Date
            AND DATEPART(HOUR, pc.ArrivalTime) = h.Hour
GROUP BY d.Date, h.Hour
ORDER BY d.Date, h.Hour;

The key is to get all the hours you need:
SELECT  [Hour] = Number
FROM    dbo.Numbers
WHERE   Number >= 0
AND     Number < 24

And all the days that you need in your range:
SELECT  Date = DATEADD(DAY, Number, @TrendStartDate)
FROM    dbo.Numbers
WHERE   Number < DATEDIFF(DAY, @TrendStartDate, @TrendEndDate)

Then cross join the two, so that you are guaranteed to have all 24 hours for each day you want. Finally, you can left join to your call table to get the count of calls.
Example on DB<>Fiddle
Answer: The basic idea is that you use a table containing numbers from 0 to 23, and left join that to your data table:
WITH CTE AS
(
    SELECT TOP 24 ROW_NUMBER() OVER(ORDER BY @@SPID) - 1 As TheHour
    FROM sys.objects
)

SELECT  @TrendStartDate
        ,isd.Name
        ,isd.Call_ID
        ,isd.callType
        ,TheHour
FROM CTE
LEFT JOIN [PHONE_CALLS] ISD WITH (NOLOCK)
    ON DATEPART(HOUR,isd.ArrivalTime) = TheHour
    AND CallType = 'Incoming'
    AND Name NOT IN ('DefaultQueue')
    AND CAST(ArrivalTime as DATe) BETWEEN @TrendStartDate AND @TrendEndDate

If you have a tally table, you should use that. If not, the cte will provide you with numbers from 0 to 23.
Comment: sys.objects will get locked. Never never use it to generate numbers in production, it will create problems.Use another table (as you suggest) or type the hours manually either with STRING_SPLIT or a UNION ALL:
SELECT TheHour = CONVERT(TINYINT, value) FROM STRING_SPLIT('0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23', ',')
Comment: ... or use `with(nolock)` hint, because here it can't do any harm. @JarleBjørnbeth good point, though.
Answer: You can use SQL SERVER recursivity with CTE to generate the hours between 0 and 23 and then a left outer join with the call table
You also use any other Method mentioned in this link to generate numbers from 0 to 23
Link to SQLFiddle
    set dateformat ymd
    declare @calls as table(date date,hour int,calls int)

    insert into @calls values('2020-01-02',0,66),('2020-01-02',1,888),
('2020-01-02',2,5),('2020-01-02',3,8),
    ('2020-01-02',4,9),('2020-01-02',5,55),('2020-01-02',6,44),('2020-01-02',7,87),('2020-01-02',8,90),
    ('2020-01-02',9,34),('2020-01-02',10,22),('2020-01-02',11,65),('2020-01-02',12,54),('2020-01-02',13,78),
    ('2020-01-02',23,99);

    with cte as (select 0 n,date from @calls union all select 1+n,date from cte where 1+n <24)
    select distinct(cte.date),cte.n [Hour],isnull(ca.calls,0) calls from cte left outer join @calls ca on cte.n=ca.hour and cte.date=ca.date


variance of number of steps in markov chain (rook move to top right)

Question: I encountered this problem while studying Markov chains and I want to calculate the variance of the problem, i.e. variance of number of steps that a random walker rook make to reach from down-left square of a chess board to the top-right square for the fist time.
Update: I found the answer in wikipedia.
$$
N = (\begin{bmatrix}
   1 & 0 \\
   0 & 1 \\
  \end{bmatrix}-\begin{bmatrix}
   6/7 & 1/7 \\
   1/2 & 3/7 \\
  \end{bmatrix})^{-1}=\begin{bmatrix}
   56 & 14 \\
   49 & 14 \\
  \end{bmatrix}
$$
Which 56+14=70 is the expected number of visits to states 0 and 1 before trapping, starting from state 0. Now for variance:
$$
t=\begin{bmatrix}
   56 & 14 \\
   49 & 14 \\
  \end{bmatrix}
  \begin{bmatrix}
   1 \\
   1 \\
  \end{bmatrix}=\begin{bmatrix}
   70 \\
   63 \\
  \end{bmatrix} \\
(2\begin{bmatrix}
   56 & 14 \\
   49 & 14 \\
  \end{bmatrix}-\begin{bmatrix}
   1 & 0 \\
   0 & 1 \\
  \end{bmatrix})\begin{bmatrix}
   70 \\
   63 \\
  \end{bmatrix}-\begin{bmatrix}
   4900 \\
   3969 \\
  \end{bmatrix}=14\begin{bmatrix}
   331 \\
   328 \\
  \end{bmatrix}
$$
Comment: Did you try to use the approach explained for the mean in the other answer?
Comment: I really liked to use a more intuitive approach like the other answer and I tried to compute $E[x^2]$ but I couldn't formulate it that way. I have no clear mind on how to relate $x^2$ to number of steps, x.
Answer: The technique used to solve the other question shows that the generating function of the number of steps $T$ is such that $$E((1-s)^T)=\frac{(1-s)^2}{1+68s+29s^2},$$ from which the expansion of the RHS up to order $s^2$ yields $E(T)=70$ and $E(T^2)=9534$, hence $$\mathrm{var}(T)=4634.$$
Comment: Where can I find a good resource to study more this approach? --thanks


keysize for Release.gpg?

Question: What is the required keysize for generating Debian Release.gpg files?
Answer: I don't believe there is a specific key size required.  It's just a detached cleartext GPG signature.  If you describe in more detail the problem you're having, perhaps someone could be of more assistance.
Comment: I am not having a specific... at least not yet. I am in the process of signing my Debian repos and I need to generate some gpg keys.
Comment: I would go with "whatever you feel comfortable with, from a standard cryptographic key length / risk analysis".

keysize for Release.gpg?