I need to find the probability that a random permutation of n elements has exactly k fixed points but I am confused on how to do so.   I have found this formula but I don't understand how to derive it.  $D_{n,k}= \frac{n!}{k!}\sum_{i=0}^{n-k}\frac{(-1)^i}{i!}$  I know there are $nCk$ choices for the k fixed points but don't know how to calculate the number of derangement's on the remaining $n-k$ elements. I know that the total number of permutations is $n!$ so I will need to divide the above formula by $n!$ to find the total probability.
I'm looking for the method by which the partial derangement formula $D_{n,k}$ was derived. I can determine the values for small values of N empirically, but how the general case formula arose still alludes me.  Any links/books or an explanation will be appreciated.  The formula is:  $D_{n,k} = {n \choose k}!(n-k)$  Links:
Move rigidbody using WASD keys but rotate it based on camera/mouse movement I am very new to unity and my scripts are based on some scripts found on the web.   I want to make a first person view so the camera is attached to my rigidbodys head. Then i want to move my rigidbody based on keyboard input (wasd) and rotate it using the mouse movement.  Until now, i used the following code for moving my rigidbody:  void Update() {      /* calculate rigidbody movement */     movement = new Vector3( Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")).normalized;      /* calculate mouse look to rotate the rigidbody*/     mouseDelta = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));     mouseDelta = Vector2.Scale(mouseDelta, new Vector2(sensitivity * smoothing, sensitivity * smoothing));     smoothV.x = Mathf.Lerp(smoothV.x, mouseDelta.x, 1f / smoothing);     smoothV.y = Mathf.Lerp(smoothV.y, mouseDelta.y, 1f / smoothing);     mouseLook += smoothV;  }  void FixedUpdate() {         /* apply rigidbody movement from Update() */     transform.Translate( movement * moveSpeed * Time.deltaTime );             /* apply rigidbody rotation from Update() */     transform.localRotation = Quaternion.AngleAxis(mouseLook.x, transform.up);             /* apply camera rotation from Update() */     Camera.main.transform.localRotation = Quaternion.AngleAxis(-mouseLook.y, Vector3.right);    }   I learned today that i dont have to move a rigidbody's transform but now i am totally confused and it seems i have to restart my whole (first!) project.  So when i use MovePosition and MoveRotation, how do i rotate it based on the camera perspective/mouse movement?  I think the movement Vector is ok so i can simply rewrite the FixedUpdate to something like  rigidbody.MovePosition(movement * speed * Time.deltaTime)   but i am totally stuck on how to apply the camera rotation to my rigidbody to use it like  void FixedUpdate() {      /* move the rigidbody */                rigidbody.MovePosition(movement * moveSpeed * Time.deltaTime);     /* rotate the camera */     camera.transform.localRotation = Quaternion.AngleAxis(-mouseLook.y, Vector3.right);      /* but how can i rotate the rigidbody based on the cameras rotation??? */     rigidbody.MoveRotation(?????);  }   I hope its clear what i want, thank you! I have two $2\times 2$ matrices, $A$ and $B$, with the same determinant. I want to know if they are similar or not.  I solved this by using a matrix called $S$: $$\left(\begin{array}{cc} a&amp; b\\ c&amp; d \end{array}\right)$$ and its inverse in terms of $a$, $b$, $c$, and $d$, then showing that there was no solution to $A = SBS^{-1}$. That worked fine, but what will I do if I have $3\times 3$ or $9\times 9$ matrices? I can't possibly make system that complex and solve it.  How can I know if any two matrices represent the "same" linear transformation with different bases?  That is, how can I find $S$ that change of basis matrix?  I tried making $A$ and $B$ into linear transformations... but without the bases for the linear transformations I had no way of comparing them.  (I have read that similar matrices will have the same eigenvalues... and the same "trace" --but my class has not studied these yet. Also, it may be the case that some matrices with the same trace and eigenvalues are not similar so this will not solve my problem.)  I have one idea. Maybe if I look at the reduced col. and row echelon forms that will tell me something about the basis for the linear transformation? I'm not really certain how this would work though? Please help. What is an SE "day"? When does each day start? When does a day start on the Stack Exchange network? Some badges (Enthusiast, , ) and voting limits are bound by and relate heavily to the concept of a day. Do days correspond to calendar days? What time zone is used?  Related Toggle wireframe mode with hotkey I often need to select a number of rows from each group in a result set.  For example, I might want to list the 'n' highest or lowest recent order values per customer.  In more complex cases, the number of rows to list might vary per group (defined by an attribute of the grouping/parent record). This part is definitely optional/for extra credit and not intended to dissuade people from answering.  What are the main options for solving these types of problems in SQL Server 2005 and later? What are the main advantages and disadvantages of each method?  AdventureWorks examples (for clarity, optional)   List the five most recent recent transaction dates and IDs from the TransactionHistory table, for each product that starts with a letter from M to R inclusive. Same again, but with n history lines per product, where n is five times the DaysToManufacture Product attribute. Same, for the special case where exactly one history line per product is required (the single most recent entry by TransactionDate, tie-break on TransactionID. What is the relation between normal extension and separable extension? What is the relation between normal extension and separable extension? Let F be the algebraic extension of K, if F is a separable extension of K,if and only if F is a normal extension of K? is this correct? primes whose difference is a multiple of $n$ Differential Equations: solve the system Solve the following system:   $$dx/dt=-.2(y-2)$$ $$dy/dt=.8(x-2)$$  This is what I have so far, but I got stuck.. $$\begin{eqnarray} dx/dt&amp;=&amp;-.2y-.4\\ x'&amp;=&amp;-.2y-.4\\ x'+.4&amp;=&amp;-.2y\\ y&amp;=&amp;-x/2'-2\\ y&amp;=&amp;-x''/2-2\\ \\ dy/dt&amp;=&amp;.8(x-2)\\ dy/dt&amp;=&amp;.8x-1.6\\ y'&amp;=&amp;.8x-1.6\\ -x''-2&amp;=&amp;.8x-1.6\\ -x''&amp;=&amp;.8x+.4\\ x''+16x+.8&amp;=&amp;0 \end{eqnarray}$$  when I used the quadratic formula I got stuck. Is this correct so far? Can someone finish it off for me? I added a user to a group, but group permissions on files still have no effect GRUB and LILO both fail to install to NVMe hard disk when installing Debian What are best practices for blocking UI when application is busy Optimizing a "black box" function: Linear Regression or Bayesian Optimization... what's the difference? Goal: I have a function $f(x,y)=z$ (two variables for illustration only) which I know almost nothing about--it has a compact domain which I can determine, it is non-negative, and bounded above.  My goal is to find the maximum value $f(x,y)$ takes on its domain.  I can query the function and I know the values at a few points: $f(x_1, y_1)=z_1, f(x_2, y_2)=z_2,..., f(x_n, y_n)=z_n$.  Optimization via Linear Regression:  I have used linear regression (and related methods like the lasso) to model functions like this in the past; this is the method that I am very comfortable with.  Typically, I might try to find a polynomial (of degree $k$) which relatively accurately models the data. The end result would be to say that:   $$f(x,y)\approx \beta_1 + \beta_2 x + \beta_3 y + \beta_4 x^2 + \beta_5 xy + \beta_6 y^2 + ... + \beta_{m}y^{k}.$$  Determining the coefficients is done by solving the .  The "best degree" for the polynomial might be determined using $k$-fold cross validation.  Once the "best" polynomial has been determined, one can choose any of a number of methods to optimize it (Newton's method, gradient descent, hill climbing, etc).  Then, if all goes well, the optimal value on the polynomial corresponds to an optimal value of $f(x,y)$.  Bayesian Optimization:  Recently, I was describing this technique (linear regression) to a colleague who asked: "What is the difference between that and Bayesian Optimization?"  I've been attempting to answer this question for the last couple days, and so far I don't have anything really conclusive.  After reading , trying to read  and getting stuck reading  I think I understand the following about BO:   Start with a prior (a guess as to what family of functions the black box belongs to... or at least some family of functions which you believe might be able to describe $f$ well).  It looks using a  as a prior is popular. Specify whatever is needed to build your prior (for GP this is a covariance function). As you go along, you maintain two evolving functions, a "mean" function $m(x,y)$ and a "confidence interval" function $c(x,y)$.  Basically, you can predict the value at any point by evaluating $m(x,y)$ and you are confident that $f(x,y)\in [m(x,y)-c(x,y), m(x,y)+c(x,y)]$. Bayesian optimization provides a systematic way of updating/exploiting the model by alternatively selecting points where the confidence interval is wide (you are very uncertain about the value) or at optimal points on the model $m(x,y)$.   My Question: Is it fair/correct to say that the major difference between Bayesian Optimization and simply optimizing the linear regression model is that Bayesian Optimization provides the systematic way of sampling with the goal of optimizing the model and reducing uncertainty whereas the linear regression model ignores the idea of uncertainty and doesn't explicitly provide a means of updating the model?  Said another way, is the linear regression model an example of what might be a "mean" function $m(x,y)$ in Bayesian Optimization?  If I stick with linear regression, specify how to compute the uncertainty, and provide a means of updating/improving the model (exploit/explore) am I just doing Bayesian Optimization (without calling it that)?  Background: My background is in pure mathematics (graph theory) but my new job has me working with a lot of data (so I'm self learning statistics).  With that in mind, my statistics vocabulary is somewhat limited (so I appreciate answers that either avoid technical terminology or briefly explain any technical terminology used)--for example, Monday was the first time I heard/read the word "prior" used in a stats sense and I'm still not 100% sure I understand that correctly. Suspend process without killing it So I've got a persistent program running in the background. Killing it just causes it to restart with a different PID. I'd like to suspend it (put it to sleep without actually killing it). Does kill -9 do this? If not, how should this be done? As you can see in object mode there are 4 vertices that have separated the front of the cartridge into multiple faces when I use boolean modifiers on cartridge.001. How can I fix this?  I imagine it has to do with good topology.  Here's the cartridge in object mode showing faces:    Here is the cartridge with the unwanted vertices:    Attached is the .blend How do I time a method's execution in Java? How do I get a method's execution time?   Is there a Timer utility class for things like timing how long a task takes, etc?     Most of the searches on Google return results for timers that schedule threads and tasks, which is not what I want. Determining the name of the VMware host of a VM guest - from the guest Is it possible to determine the name of the VMware host (ESX or ESXi) that my guest resides in, from within the guest itself?  I would expect this to be possible via VMware Tools, but am not sure where to look. What are the shortcomings of the Mean Absolute Percentage Error (MAPE)? The  () is a common accuracy or error measure for time series or other predictions,  $$ \text{MAPE} = \frac{100}{n}\sum_{t=1}^n\frac{|A_t-F_t|}{A_t}\%,$$  where $A_t$ are actuals and $F_t$ corresponding forecasts or predictions.  The MAPE is a percentage, so we can easily compare it between series, and people can easily understand and interpret percentages.  However, I hear that the MAPE has drawbacks. I'd like to understand these drawbacks better so I can make an informed decision about whether to use the MAPE or some alternative like the MSE (), the MAE () or the MASE (). Is it possible that your friends can join your Hamachi server when they don't have Hamachi? Does anyone know how to do that??!! Is there any bidirectional 5v-3.3v level shifter? Why can we apply the $E=hf$ equation for electrons? So in my textbook, it states that the $E=hf$ equation applies to electrons, and all particles, not just photons.   But in order to prove this, wouldn't these particles need to have zero mass, to satisfy $E=pc$ from Einstein's equation?  In Einstein's theory of relativity $E^2= p^2c^2 + m^2c^4$, we get $E=pc$ because we consider the mass to be zero.   For $E=hf$ to work for other particles, don't we need to assume electrons have zero rest mass?