text:
# Deep Trouble – Neural Networks Easily Fooled

Deep Neural Networks (DNNs) always leave me with a vague uneasy feeling in my stomach.  They seem to work well at image recognition tasks, yet we cannot really explain how they work.  How does the computer know that image is a fish, or a piano, or whatever?  Neural networks were originally modeled after how biological neurons were thought to work, although they quickly became a research area of their own without regard to biological operation.

Well, it turns out that DNNs don’t work at all like human brains.  A paper by Nguyen, et al 1 explores how easy it is to create images that look like nothing (white noise essentially) to the human brain, and yet are categorized with 99%+ certainty as a cheetah, peacock, etc. by DNNs that perform at human levels on standard image classification libraries.  Here a small sample of images from their paper:

The researchers created the false images through an evolutionary algorithm that seeks to modify existing images through mutation and combination in order to improve on a goal, in this case to find images that would score highly with a DNN classifier (“fooling images”).  They used a couple of methods, both of which worked.  The direct method, illustrated in the top two images, works by direct manipulation of the pixels in an image file.  The indirect method, illustrated in the bottom two images, works by using a series of formulas to generate the pixels; the formulas were then evolved.  The idea was to create images that looked more like images and less like random noise.  In both cases, the researchers found it easy to come up with images that fooled the DNN.

Their results also seemed robust.  They performed various trials with random starting points, they even added their fooling images to the training sets, so as to warn the DNN that these were incorrect.  Even after doing that, they were still able to find other fooling images that were misclassified by the new “improved” DNN.  They even repeated this process as many as 15 times, all to no avail.  The DNNs were still easily fooled.

As the authors point out, this ability of DNNs to be fooled has some serious implications for safety and security, for example in the area of self-driving cars.  For real world results, see the Self-driving car hack.

There is something going on here that we do not fully understand.  Researchers are starting to look into what features a DNN is really considering – which may help us to improve or alter the game for image recognition. Until then, pay attention to that pit in your stomach.

Notes:

1. A. Nguyen, J Yosinkski, and J. Clune, Deep Neural Networks are Easily Fooled: High Confidence Predictions for Unrecognizable Images, Computer Vision and Pattern Recognition (CVPR ’15), IEEE, 2015

# Bitcoin Network Hash Rates. Where are you, Bitcoin cash?

The Bitcoin blockchain just split in two.  What is Hash Power and where did it go?  With the split, people are discussing the terms “Hash Power” and trying to decide how many miners are mining each blockchain.  We will present the basic equations for working out these issues, and estimate the relative hash powers mining the 2 chains.

# What is the Hash Rate?

Mining is the process by which the bitcoin blockchain is kept secure.  Briefly, the blockchain is a public ledger that everyone “agrees” on that contains the entire history of all bitcoin transaction since time began.  Miners do work (think mining gold) in order to add blocks to the blockchain, for which they get rewarded.  Bitcoin uses what’s called a Proof-of-Work system for mining, other methods used on other cryptos include Proof-of-Stake.

The basic work that the miner has to do is take a batch of current transactions, and find a number, called a nonce, so that the data (in a predetermined format) hashes to a number that is less than a target.

Let’s dissect these pieces one at a time:

1. nonce: named because originally it was a “number used once”, but here it is just a number that the miner is free to pick.  Why the miner would want to pick different ones will be clear shortly.
2. hash: A hash is a function that takes an arbitrary length piece of data and computes a digest, or shorter abbreviation for the data. Note: for the purists out there, we are just considering cryptographic hashes.  Bitcoin uses the hash SHA256, which is a particular hash that produces a 256 bit digest.  The idea of a good hash is that it is very hard to manipulate the data going into the hash to produce any particular hash – effectively it looks like a random number produced from the data (which is always the same for the same data).
3. target: this is a 256 bit number.  Let’s call it T.  It gets calculated a special way on the Bitcoin network, as will be described later.

Now, to rehash things, so to speak:

To successfully add a block to the bitcoin blockchain, the miner must be the first person to find a nonce N, so that:
$\textrm{SHA256}(\textrm{SHA256}(\textrm{blockdata}, N)) < T$
where blockdata represents the transactions that the miner wants to include in the block. The nonce is in a certain place in that data, but here we call it out as a separate argument to make it clear that the results varies with N. Different miners might want to include different transactions for a variety of reasons, which we don’t need to go into here. Because of the properties of the SHA256 hash, this problem can only be solved (based on our current understanding of SHA256) by repeatedly trying different values of N until we find one that results in our target being hit. The miner has no idea which values of N are better than any others (because the hash is “random”), so they just try them in sequence, 0, 1, 2, 3, … until they find one that gives a hash value less than T. You might ask “why the double hash?”. Excellent question. No one knows for sure, but that’s just the way it is.

How long does it take for a miner to find an acceptable nonce?  Suppose that the miner can calculate H double-hashes per second.  Then, since the result of SHA256 is effectively a random number from 0 to $$2^{256}-1$$, the probability of any given attempt satisfying the target is:
$prob=\frac{T}{2^{256}}$
and the expected time $$E(X)$$to find a new block would be
$E(X)=\frac{2^{256}}{T \cdot H}$

# Difficulty

How is the target T calculated?  The target gets adjusted every 2016 blocks – the idea is that the average time for each block should be 10 minutes.  Thus, if there are so many miners that blocks are found much more frequently, say every 2 minutes, the target T would get adjusted (made smaller), so that the new block times become approximately 10 minutes.
Here are the details of the calculation. It uses something called the Difficulty (D), which is kind of the inverse of the T. That is, the higher difficulty, the lower the target T. You can find the current difficulty from a variety of websites, bitcoinwisdom.com has a nice graph of its history.

Remark: There is something called the packed difficulty (32 bits), which you may see. It is a floating-point representation of the difficulty which is shorter. For example, a packed difficulty 0x1d00ffff becomes:
$D_1=\text{0x00ffff} \cdot 2^{8 (\text{0x1d} – 3)}=\text{0xffff}\cdot 2^{208}=\text{0x00000000ffff0000000000000000000000000000000000000000000000000000}$
where there should be 52 0’s after the ffff. You can check my counting if you want.
This particular value of difficulty is called difficulty-1, $$D_1$$.  It is the highest possible difficulty, and it used to compute the target from the current difficulty D.
$T=\frac{D_1}{D}$
If the current difficulty were $$D_1$$, the target would be 1, and the SHA double hash would have to be 0. With a probability of that happening on each try of $$1/2^{256}$$ or $$p=8.636 \cdot 10^{-78}$$, that’s pretty hard! The expected number of hashes to find a block for a difficulty D is:
$\frac{2^{256}}{T}=\frac{D\cdot 2^{256}}{(2^{16}-1)2^{208}}\approx D\cdot2^{32}$
Let X be the time to find a block, we have the following relationships:
\begin{align}
T&=\frac{2^{256}}{D\cdot2^{32}}=\frac{2^{224}}{D}\\
\textrm{E}(X)&=\frac{2^{256}}{T \cdot H}=\frac{D \cdot 2^{32}}{H}
\end{align}
We can reverse the last equation to to estimate the number of hashes per second that a particular time to find a block represents:
$\text{hashpower (estimate)}=\frac{D\cdot 2^{32}}{X}$
Now, when we see the word “estimate”, we should be thinking “what is its variance?” The estimate here is zero-mean-error, but its variance is quite high. It turns out (I won’t prove it here) that if we expect $$\lambda$$ blocks per second, then, for the time per block X:
\begin{align}
\textrm{E}(X)&=\frac{1}{\lambda} \\
\textrm{Var}(X)&=\frac{2}{\lambda^2}
\end{align}
Now, if we average block times over M blocks, the variance can be reduced per the usual formula:
\begin{align}
\textrm{Var}_M(X)&=\frac{2}{\lambda^2 \cdot M} \\
\textrm{std-dev}_M(X)&=\sqrt{\frac{2}{M}}\cdot \textrm{avg}(X)
\end{align}
For an example, the block times for bitcoin are generally around 10 minutes. If we average various numbers of past block times, we get the following standard deviations:

 Number of Blocks Std Deviation of Average Block Time 6 5.77 min 10 4.47 min 20 3.16 min

Thus, we can see that even with looking at the last 20 blocks, we have a great uncertainty in the actual hash power that is operating to produce that block.  Let’s now look at the current block times for Bitcoin and Bitcoin cash and estimate the hash power operating on the chains.  Note that if mining hashpower is switching between Bitcoin and Bitcoin cash, it will take some time to determine that from the data – since we will want more than 20 blocks to average over.

Update 6 Aug 2017 10:47 AM EST:  blocktimes and difficulty dropped significantly (and BTC closer to expected average):

 Bitcoin (BTC) Bitcoin Cash (BCC) Avg Block Time (min) Std Dev Avg Block Time (min) Std Dev Last 39 (BTC) 20 (BCC) blocks as of 10:47AM EST 6 Aug 2017 9.95 2.25 20.25 6.40 Difficulty 860 221 984 436 144 323 701 657 Estimated Hash Power (double-hash/sec) 6.19 * 10^18 5.1 * 10^17 Relative Hash Power (BTC=1.0) 1.0 .082

Note: this is current as of 5 Aug 2017 12:42 AM EST.  I hope to have a online updating version up later.

 Bitcoin (BTC) Bitcoin Cash (BCC) Avg Block Time (min) Std Dev Avg Block Time (min) Std Dev Last 6 blocks 6.8 3.9 74.3 42.9 Last 20 blocks 6.0 1.9 76.0 24.0 Last 39 (BTC) 29 (BCC) blocks 5.7 1.5 55.6 12.6 Difficulty 860 221 984 436 225 505 642 691 Estimated Hash Power (double-hash/sec) 1.1 * 10^19 2.9 * 10^17 Relative Hash Power (BTC=1.0) 1.0 0.026

References

1. Exponential Distribution
2. Bitcoin Difficulty
3. blockchair.com (for block times)
4. A great detailed discussion of all aspects of bitcoin and other crytpocurrency concepts.
5. Discussion geared for a less technical audience

# An Investor’s View of ICOs

ICO? Initial Coin Offering.  Remind you of an IPO (Initial Public Offering)?  It is meant to.  Bancor raised $147 million in a few hours. Block.one sold$185 million of EOS tokens in 5 days.  Tezos has raised over $100 million in 2 days, with 10 more days to go and no cap. There are currently almost 20 ICOs planned for the month of July. See the sites at the bottom of this post for lists of ICOs. There are plenty of analyses to be found online about the pros and cons of the various ICOs (or token sale, or whatever name they are actually called). What I want to do is give you the perspective of a private investor on these deals – and how they compare to more traditional private investments. I have made dozens of private investments in startup companies, been involved in dozens more as a member of an investment committee, and seen probably hundreds, if not thousands, of other deals cross my monitor. There are a number of dimensions along which a deal gets evaluated. Some are: • Business plan Is this a good business to be in? • Team Are these the right people to execute the plan? • Market Is the market for this product large enough or growing fast enough to be interesting? • Price What price am I paying to get in on this opportunity? • Terms What are the fine print details on the deal? As I said above, there are plenty of other places debating the business plans and teams. Today, I want to discuss the terms. Generally, these do not get much attention in a private deal. Not because they are not important, but because they are so important that standard terms have evolved over time, and people assume that these standard terms will be included. Each one has a reason for being included. ### A Private Investment Term Sheet Let’s go through a standard private investment term sheet and see what kinds of things are in there. We will call our company the imaginative name NewCo. We will call our new coin NewCoin. I am leaving out a lot of the gory technical language here; if you want to see a full model term sheet, check out the National Venture Capital Association.  Price Example: Investors will invest$2 million in NewCo, at a $10 million fully-diluted post-money valuation, including a employee pool of 20% of the post-money capitalization. They will receive Series A Preferred Stock. Explanation: Investors will get 20% of NewCo after the financing, including all other convertible securities, such as options (this is the fully-diluted part). NewCo is setting aside 20% its shares for issuance to employees in the future. The Series A Preferred Stock is really just a label – its properties are defined by the rest of the term sheet. Dividends How and when dividends might be paid. Important to prevent the company from paying out all it’s cash in dividends to the common stockholders and not giving any to the investors. Capitalization The company’s capital structure before and after Closing is set forth in exhibit A. So everyone knows who owns what. Liquidation Preference Describes how liquidation or acquisition proceeds are split with investors. Generally there is some preference to investors. In our example, if the company were sold a month after the investment, for$5 million, the investors would receive 50% of their investment (losing $1m), but the founders/employees would walk away with$4 million, without doing anything.  To prevent this, various preferences for the investors have evolved called non-participating or particpating Preferred Stock.  Generally, the first proceeds of a liquidation go back to the investors until they receive their investment back. Conversion This allows investors to convert to Common Stock when it become advantageous. This is how they can exit the deal in an IPO, for example. Antidilution This specifies how the investors purchase price can change if the company issues shares later at a much cheaper price.  Without this, there would be no way to stop a company from issuing lots of cheap shares after an investment and diluting the investor. Information Rights Details how information will be provided to investors over time, for example, monthly financial reports, annual audits, etc.  This forces the company to keep providing information in the future. Voting Rights Specifies how various votes will be taken. Registration Rights Very technical details on how shares should be registered, relative to public offerings. Representations and Warranties Statements about the company that the founders declare are true, E.g. here are all our debts, we have no pending lawsuits, etc. Board of Directors How many members will be on the board, who will they be, how can they be changed in the future.  They are generally elected by the stockholders. Future Financing How can future financings be conducted?  Will the current investors have the right to participate in a pro rata share?  Do they have the right to approve the financing? Vesting If a Founder leaves the company 2 days after financing, should they keep all their shares?  Since the investors presumably invested because of the specific founders, they would not want to to see them leave.  Typical terms might be 25% of the stock vests after 12 months, with the rest vesting over another 3 years.  Also Founder’s rights to sell shares is restricted (also note that investors generally have restrictions on their sales as well). Employee Matters Each Founder should sign a non-compete agreement, and non-disclosure agreement (NDA), and a non-solicit agreement (that they will not hire away current employees if they leave).  Also, they agree that intellectual property developed by them for the company belongs to the company (IP Assignment).

In a private investment, money goes into NewCo, which is managed by a Board of Directors, who hires the CEO.  If all the employees walk out, they don’t take the funds of the company with them, and they lose their shares according to the vesting schedule.  While obviously not what was intended, the money would still be there, and the BOD (elected by the shareholders) could hire a new CEO and team.  They could even give the funds back to the investors and call it a day.  The BOD has a fiduciary responsibility to the investors to act in their best interests.  They could not, for instance, divide the money up among themselves.

### Compare versus ICO

Let’s now look at a typical ICO and see how these items relate.

Generally ICOs specify the price you pay for each NewCoin, generally in bitcoin (BTC) or ethereum (ETH).  But each NewCoin does not get you any ownership in a business.  The business that NewCoin is in could do well, NewCoin could become very popular and fashionable, but NewCoin has to increase in value for you to see a return.  You also do not own any future IP or technology developments that the founders/developers create [compare with IP Assignment].   Since code is almost always open-source, there is nothing proprietary about it.

In an ICO, investors have no oversight or control over what the Founder team is doing. In the case of a foundation being created, this might be up to the foundation’s directors, but again, they might not be elected or answerable to the investors.  There should be something comparable to an elected BOD.

What prevents founders and developers from walking away?  Where is the vesting?.  The distribution of NewCoin to founders is generally opaque (no cap table is generally provided) so you don’t know who owns what.  If they developers want to develop a better, competing coin based on what they learned at NewCoin, can they? [compare to non-compete agreement].  To the extent founders hold NewCoin, there would be an incentive for them to help out NewCoin, but the distribution is unknown, and without vesting they might just sit back and see others do the work.

Coins kept by founders running NewCoin could be considered like the stock held by founders in a PI.  They have incentive to make the coin increase in value.  The issue is there is no lockup to prevent them from selling, no vesting terms, and no public knowledge of their ownership.  They could sell their coins and no one knows.

ICOs are somewhat more akin to a Limited Partnership where the investors generally do not have control over the operations and details, except that in an Limited Partnership (1) there are provisions for removing General Partners (GPs) in extreme cases, and (2) the GP has a fiduciary responsibility to the LPs.  An ICO should have a mechanism for providing such a responsibility.

What if the NewCoin needs more money to finish development? In a private investment, there are ways to raise additional funds, but it is not as obvious how NewCoin does this.  They could sell some of the reserved coins (if there are any and they have value), but often the supply is fixed.  In an ICO you might be stuck.

Private companies generally stage their investment.  At each stage, money is raised to reduce risk and bring the company to a milestone that greatly changes its value.  This is more capital efficient and less risky for all concerned.  Rather than raise 100M on an idea, companies might raise $1-5M in a series A to prove out an idea or concept, then raise 10-20M in Series B, and so on. Each phase should be reducing some risk. ICOs are generally a one-shot deal. There is no first proof-of-concept stage, with later money coming with results. Lists of ICOs: # Lending Rates for Bitcoin and USD on Cryptoexchanges We are going to take a look at the current interest rates in bitcoin lending. Why is this important? In addition to being a way to make extra income from your fiat (“real” currency) or bitcoin holdings without selling them, these interest rates indicate traders sentiment about the relative values of these currencies in the future. We will look at bitcoin in this post, because it is the largest cryptocurrency, both in terms of market cap and trading volume. As of the date of this writing here are the top 4 cryptocurrencies by total market cap. Information from http://coinmarketmap.com.  Crypto-Currency Market Cap ($USD, billion) 24 Hr Trading volume ($USD, billion) Bitcoin (BTC) 45 1.0 Ethereum (ETH) 32 0.78 Ripple 11 0.18 Litecoin (LTC) 2.5 0.37 The Bitfinex Exchange is one of the exchanges that allows margin trading, and also customer lending of fiat and crytpocurrencies. They call the lending exchange funding and it works with an order book just like a regular trading exchange. Customers submit funding offers and requests, and the exchange matches the orders. So, for example, I could offer$USD800 for 4 days at .0329% per day (12% annually).  This get placed on the order book.  Someone else could accept that offer, and then the loan happens.  As the lender, I get paid interest daily at the contract rate, paid by the borrower.  Now, what does the borrower do with the proceeds?  They can’t withdraw the money from Bitfinex, this is not a general personal loan.  They could use this money to buy bitcoins on margin.  There are specific rules on how much they can borrow at purchase, and how much margin they must maintain in the future.  We won’t go into the specifics of those rules in this post, but just be aware that the exchange can liquidate, or sell, a position to maintain margin requirements.  In fact, this is what caused the recent meltdown in the Ethereum market at one exchange (GDAX) Ethereum Flash Crash, as traders had their positions liquidated automatically for margin calls.

So, show me the data!

In this chart, fUSD is the funding rate as an APR for \$USD, and fBTC is the funding rate for bitcoin (BTC). These are based on a small sample of 2 day loans actually traded on that day. The first thing to note is that the rates are quite volatile, reaching highs of over 100% (USD) and 50% (BTC) during the last year. The current rates (June 2017) are around 40% (USD) and 4% (BTC).

One more thing we might want to look at.  We might wonder about the difference between the two rates and what that means.  In economics, there is something called uncovered interest rate parity, which normally looks at the difference in interest rates between 2 currencies, say the USD and the Euro (EUR).  This difference is related to the relative inflation expected between the 2 currencies in the future.  In fact, futures contracts for the currencies should have a price related to this difference in such a way as to make arbitrage not possible.  Here is the difference graph.

Note that it switches around both sides of zero.  Between approximately 15 Mar 2017 and 1 May 2017, it was negative, meaning people were demanding higher rates to lend BTC than to lend USD.  Perhaps this is an indication that people wanted to short BTC at that time – although we don’t know which fiat currency they were shorting it against.

Another thing that we can pull from the data is the yield curve.  In the bond market, this indicates the interest rates for bonds at different maturities, for example, a 30 day, 60 day, 1 year, etc.  In the case of Bitfinex, the loans can only be made for 2-30 days, so we have a more limited set of possibilities.

You can see the curves are relatively flat, but they only go out to 30 days, so we can’t say much about 1 year rates. Note that most of the volume is at the extremes, that is 2 days or 30 days, so the numbers in between are not that meaningful.

In post to come, we will look at Bitcoin futures, to see how their pricing might be related to the uncovered interest rate parity. Stay tuned.


text:
# XeLaTeX: System font for headers only?

I know that you can use `\setmainfont` for normal text but is there any command that will apply a font only to headers (chapters, sections, subsections)?

-

## migrated from stackoverflow.comAug 22 '11 at 13:24

This question came from our site for professional and enthusiast programmers.

Using `fontspec`, you can define any font you want in XeTeX. You can then use them in the places of your choice by using the macro names you chose.

If you want to change the fonts used in sections, you can combine `fontspec` with `titlesec`. Example:

``````\usepackage{fontspec}
\usepackage{xunicode}
\defaultfontfeatures{Ligatures=TeX}
\setmainfont{Linux Libertine O}
\newfontfamily\secfont{EB Garamond}

\usepackage{titlesec}

\newcommand{\secstyle}{\secfont\large\itshape}
\titleformat{\section}%
{\secstyle} % format
{} % label
{10pt} % sep
{} % before
[\normalfont] % after
``````

will use Linux Libertine O as main font and EB Garamond as section font.

-

format: plain


text:
# Investigation of the composition of woodsmoke and methods for apportioning woodsmoke to air pollution in Launceston

Jordan, TB 2005 , 'Investigation of the composition of woodsmoke and methods for apportioning woodsmoke to air pollution in Launceston', PhD thesis, University of Tasmania.

 Preview
PDF (Complete Thesis)
Available under University of Tasmania Standard License.

| Preview

## Abstract

Launceston, a city with a population of approximately 80,000 located in the north of Tasmania, Australia, regularly experiences high levels of air pollution during winter. Ambient PM_(10) (particulate matter with an aerodynamic diameter smaller than 10 micrometres) levels exceed the Australian 24-hour guideline of 50 μg/m^3 around 20-40 times during the May to September period each year. This is generally attributed to residential woodburning, with approximately one third of households using woodheaters or open fireplaces. This thesis reports on investigations into characterising and quantifying the contribution of woodsmoke to wintertime air pollution in Launceston.
An historical record of air quality in Launceston was reconstructed using polycyclicaromatic hydrocarbons (PAHs) as surrogates for air pollution in a dated sediment core taken from the upper Tamar Estuary. The overall depth profile showed that levels of PAHs began increasing at the end of the 19th century and have been relatively steady since the 1930s. Pyrogenic source ratios similar to woodburning were found in both atmospheric and sedimentary samples, although quantification of the woodburning contribution was not possible using PAHs alone. Factors affecting atmospheric sampling of PAHs were investigated, including the impact of sampling rate, the vapour-particle phase distribution on various components of the sampling system and degradation caused by different filter media.
Because of the inability of PAHs to differentiate between fossil fuel and wood combustion there was a need to identify alternative tracers for wood combustion. A dilution tunnel was used to collect emissions from woodheaters operated with different airflow settings, and around 100 organic compounds were quantified. Although the majority of compounds were not detected in ambient air samples, levoglucosan was found to be not degraded in the atmospheric samples and was identified as a consistent tracer for woodsmoke. Levoglucosan concentrations in ambient PM_(10) indicated that woodheaters contributed about 80% of wintertime air pollution in Launceston.
To validate the use of levoglucosan as a tracer for woodsmoke, the contribution of biomass and fossil fuel sources of carbon to Launceston ambient aerosols was determined by measuring the carbon-14 content using accelerator mass spectrometry. Fossil sources had a relatively low and constant input irrespective of the particulate loading, consistent with transport-related emissions. Conversely, the biomass input, most likely from woodsmoke, was found to increase linearly with particulate loading, and contributed around 97-99% of the total organic carbon fraction of Launceston wintertime PM10. A modified combustion method was developed for samples collected on borosilicate filter media.

Item Type: Thesis - PhD Jordan, TB atmospheric contamination, air pollution, environmental chemistry, airborne particles, wood combustion Copyright 2005 the author View statistics for this item


text:
# [Rd] Potential cross-platform package building issue

Steven Ranney steven.ranney at gmail.com
Sat Jan 3 21:49:53 CET 2015

I am using 32-bit R 3.1.2 on Windows 7.

I recently conducted an R CMD check --as-cran on a recently-developed
package and received only the 'New submission' note. Research on
StackOverflow and on R-devel suggested this could be ignored. I also used
devtools::build_win() and received no notes or warnings, other than the one
mentioned previously. Lastly, I conducted an R CMD check with the
development version of R.  Further, I built the package locally with R CMD
build and R CMD INSTALL --build and everything worked as it should,
including the PDF manual.

Upon submission to CRAN, I was told that a warning was thrown:

This fails to make its manual:
This typically indicates Rd problems.
LaTeX errors found:
! Missing $inserted. <inserted text>$
l.682 }{}
! Missing } inserted.
<inserted text>
}
l.682
}{}
...

The line appears to be
\widehat{R_1} =
\frac{\sum\limits_{i=1}^n{c_i/n}}{\sum\limits_{i=1}^n{L_i/n}}

I asked for assistance in resolving this issue as I could not replicate the
WARNING.  Another user could replicate the warning on Ubuntu 12.04 but was
able to resolve the issue by removing the DOS end-of-line markers (^M or
Ctrl-M) from the .Rd file.  Neither he nor I could find anything in the R
Extensions Manual that discussed removing end-of-line markers.

http://stackoverflow.com/questions/27756679/cran-finds-an-warning-that-r-cmd-check-as-cran-does-not

Is this an obscure cross platform issue?  If so, I would have thought that
someone else would have already discovered this.  If this is normal
behavior, is there a simple way to remove these end of line markers so I
can minimize WARNINGS from CRAN in the future?

Thanks -

Steven Ranney

[[alternative HTML version deleted]]


text:
# Count index pairs which satisfy the given condition in C++

We are given an array of permutation of first N natural numbers. The goal here is to find the index pairs of elements that satisfy the condition mentioned below −

If an array is Arr[], then i,j are indexes, count element pairs such that Arr[i]+Arr[j]=max(Arr[x]) such that i<=x<=j.

That is, the sum of Arr[i] and A[j] is equal to the maximum element occurring between these two segments.

## Input

Arr[]= { 2,4,1,3,6,5 }

## Output

Count of index pairs which satisfy the given condition:1

Explanation − The sum of pairs is given −

2+4=6, 6 is maximum but not between 2 and 4.

2+1=3, 3 is not in between 2 and 1 and maximum between them is 4.

2+3=5, 5 is not in between 2 and 3 and maximum between them is 4.

2+6=8, 8 is not in between 2 and 6 and maximum between them is 4.

Similarly

1+5=6, 6 is in between 1 and 5 and maximum between them is 6.

Out of all only 1 pair is present that satisfies the condition.

## Input

Arr[]= { 1,2,5,4,3 }

## Output

Count of index pairs which satisfy the given condition:2

Explanation − The sum of pairs is given −

1+5=6, 6 is maximum but not between 1 and 5.

1+4=5, 5 is in between 1 and 4 and the maximum between them is 5.

2+3=5, 5 is in between 2 and 3 and the maximum between them is 5.

1+3=4, 4 is in between 1 and 3 but the maximum between them is 5.

Out of all 2 pairs are present that satisfy the condition.

## Approach used in the below program is as follows

• Integer array Arr[] stores the numbers and size its length.

• Function countPairs(int A[],int n) takes an array and its size n as input and returns the count of pairs which satisfy the above condition..

• Variable count is used to store the initial value 0 for such pairs.

• Initialize max1 with the first element and its index in maxindex as 0 to store the value and index of maximum value found so far.

• Start traversing the array using for loop.

• Inside nested for loop if given A[j]>=max1 then update max1 and its index with j.

• For each pair of A[i] and A[j] if sum is equal to max1 and index maxindex is in between i and j, then increment count as condition is satisfied.

• After the end both loops return the result present in count.

## Example

Live Demo

// CPP implementation of the approach
#include<bits/stdc++.h>
using namespace std;
// Function to return the count of
// required index pairs
int countPairs(int A[], int n){
// To store the required count
int count = 0;
int i,j,k;
int max1=A[0];
int maxindex=0;
for ( i = 0; i<n-1; i++){
for(j=i+1;j<n;j++){
if(A[j]>=max1){
max1=A[j];
maxindex=j;
}
if(A[i]+A[j]==max1 && maxindex>=i && maxindex<=j)
count++;
}
}
// Return count of subsegments
return count;
}
int main(){
int Arr[] = {3, 4, 6, 1, 5, 2};
int size =6;
cout <<endl<<"Count of index pairs which satisfy the given condition:"
<<countPairs(Arr,size);
return 0;
}

## Output

Count of index pairs which satisfy the given condition: 1


text:
## Equivalence of Norms

I'm somewhat stuck with the simple proof of the following:

Let the (Lebesgue-)measure of some $\Omega$ be finite and $1 \le p \le q \le \infty$.
Then for all $u \in L^q(\Omega)$ it is also true that $u \in L^p(\Omega)$, whereby
$||u||_p \le \text{meas}(\Omega)^{\frac{1}{p}-\frac{1}{q}}||u||_q$;
for $q=\infty$ set $\frac{1}{q}:=0$.

Proof: If $q=\infty$, then $||u||^p_p=\int_{\Omega}|u(x)|^p\,dx \le \text{meas}(\Omega) \sup_{\Omega \setminus N}|u|^p$, where N ist a large enough null set.

If $q<\infty$, then the Hölder inequality should help, but I'm somewhat confused by the suitable choice of exponents.


text:
# APEX Calculus: for University of Lethbridge

## Section8.4Modeling with Differential Equations

In the first three sections of this chapter, we focused on the basic ideas behind differential equations and the mechanics of solving certain types of differential equations. We have only hinted at their practical use. In this section, we use differential equations for mathematical modeling, the process of using equations to describe real world processes. We explore a few different mathematical models with the goal of gaining an introduction to this large field of applied mathematics.

### Subsection8.4.1Models Involving Proportional Change

Some of the simplest differential equation models involve one quantity that changes at a rate proportional to another quantity. In the introduction to this chapter, we considered a population that grows at a rate proportional to the current population. The words in this assumption can be directly translated into a differential equation as shown below.
There are some key ideas that can be helpful when translating words into a differential equation. Any time we see something about rates or changes, we should think about derivatives. The word “is” usually corresponds to an equal sign in the equation. The words “proportional to” mean we have a constant multiplied by something.
The differential equation in Figure 8.4.1 is easily solved using separation of variables. We find
\begin{equation*} p = Ce^{kt}\text{.} \end{equation*}
Notice that we need values for both $$C$$ and $$k$$ before we can use this formula to predict population size. We require information about the population at two different times in order to fully determine the population model.

#### Example8.4.2.Bacterial Growth.

Suppose a population of e-coli bacteria grows at a rate proportional to the current population. If an initial popluation of 200 bacteria has grown to 1600 three hours later, find a function for the size of the population at time $$t\text{,}$$ and use it to predict when the population size will reach 10,000.
Solution 1. Video solution
Solution 2.
We already know that the population at time $$t$$ is given by $$p = Ce^{kt}$$ for some $$C$$ and $$k\text{.}$$ The information about the initial size of the population means that $$p(0)=200\text{.}$$ Thus $$C=200\text{.}$$ Our knowledge of the population size after three hours allows us to solve for $$k$$ via the equation
\begin{equation*} 1600 = 200e^{3k}\text{.} \end{equation*}
Solving this exponential equation yields $$k =\ln(8)/3 \approx 0.6931\text{.}$$ The popluation at time $$t$$ is given by
\begin{equation*} p = 200 e^{(\ln(8)/3)t}\text{.} \end{equation*}
Solving
\begin{equation*} 10000 = 200e^{(\ln(8)/3)t} \end{equation*}
yields $$t =(3\ln(50))/\ln(8) \approx 5.644\text{.}$$ The population is predicted to reach 10,000 bacteria in slightly more than five and a half hours.
Another example of porportional change is Newton's Law of Cooling. The laws of thermodynamics state that heat flows from areas of higher temperature to areas of lower temperature. A simple example is a hot object that cools down when placed in a cool room. Newton's Law of Cooling is the simple assumption that the temperature of the object changes at a rate proportional to the difference between the temperature of the object and the ambient temperature of the room. If $$T$$ is the temperature of the object and $$A$$ is the constant ambient temperature, Newton's Law of Cooling can be expressed as the differential equation
\begin{equation*} \frac{dT}{dt} = k(A - T)\text{.} \end{equation*}
This differential equation is both linear and separable. The separated form is
\begin{equation*} \frac{1}{A-T}\,dT = k\,dt\text{.} \end{equation*}
Then an implicit definition of the temperature is given by
\begin{equation*} -\ln\abs{A-T} = kt + C\text{.} \end{equation*}
If we solve for $$T\text{,}$$ we find the explicit temperature
\begin{equation*} T = A-Ce^{-kt}\text{.} \end{equation*}
Though we didn't show the steps, the explicit solution involves the typical process of renaming the constant $$\pm e^{-C}$$ as $$C\text{,}$$ and allowing $$C$$ to be positive, negative, or zero to account for both cases of the absolution value and to catch the constant solution $$T=A\text{.}$$ Notice that the temperature of the object approaches the ambient temperature in the limit as $$t\to\infty\text{.}$$

#### Example8.4.3.Hot Coffee.

A freshly brewed cup of coffee is set on the counter and has a temperature of 200$$^\circ$$ Fahrenheit. After 3 minutes, it has cooled to 190$$^\circ\text{,}$$ but is still too hot to drink. If the room is 72$$^\circ$$ and the coffee cools according to Newton's Law of Cooling, how long will the impatient coffee drinker have to wait until the coffee has cooled to 165$$^\circ\text{?}$$
Solution 1. Video solution
Solution 2.
Since we have already solved the differential equation for Newton's Law of Cooling, we can immediately use the function
\begin{equation*} T = A - Ce^{-kt}\text{.} \end{equation*}
Since the room is 72$$^\circ\text{,}$$ we know $$A = 72\text{.}$$ The initial temperature is 200$$^\circ\text{,}$$ which means $$C = -128\text{.}$$ At this point, we have
\begin{equation*} T = 72 + 128e^{-kt} \end{equation*}
The information about the coffee cooling to 190$$^\circ$$ in 3 minutes leads to the equation
\begin{equation*} 190 = 72 + 128e^{-3k}\text{.} \end{equation*}
Solving the exponential equation for $$k\text{,}$$ we have
\begin{equation*} k = -\frac{1}{3}\ln \left(\frac{59}{64}\right) \approx 0.0271\text{.} \end{equation*}
Finally, we finish the problem by solving the exponential equation
\begin{equation*} 165 = 72 + 128e^{\frac{1}{3}\ln \left(\frac{59}{64}\right)t}\text{.} \end{equation*}
The coffee drinker must wait $$\displaystyle t = \frac{3 \ln \left(\frac{93}{128}\right)}{\ln \left(\frac{59}{64}\right)} \approx 11.78$$ minutes.
We finish our discussion of models of proportional change by exploring three different models of disease spread through a population. In all of the models, we let $$y$$ denote the proportion of the population that is sick ($$0 \leq y \leq 1$$). We assume a proportion of $$0.05$$ is initially sick and that a proportion of $$0.1$$ is sick 1 week later.

Suppose a disease spreads through a population at a rate proportional to the number of individuals who are sick. If 5% of the population is sick initially and 10% of the population is sick one week later, find a formula for the proportion of the popoulation that is sick at time $$t\text{.}$$
Solution.
The assumption here seems to have some merit because it matches our intuition that a disease should spread more rapidly when more individuals are sick. The differential equation is simply
\begin{equation*} \frac{dy}{dt} = ky\text{,} \end{equation*}
with solution
\begin{equation*} y = Ce^{kt}\text{.} \end{equation*}
The conditions $$y(0)=0.05$$ and $$y(1) = 0.1$$ lead to $$C = 0.05$$ a and $$k = \ln(2)\text{,}$$ so the function is
\begin{equation*} y = 0.05e^{(\ln(2)t}\text{.} \end{equation*}
We should point out a glaring problem with this model. The variable $$y$$ is a proportion and should take on values between 0 and 1, but the function $$y = 0.05e^{2t}$$ grows without bound. After $$t \approx 4.32$$ weeks, $$y$$ exceeds 1, and the model ceases to make physical sense.

Suppose a disease spreads through a population at a rate proportional to the number of individuals who are not sick. If 5% of the population is sick initially and 10% of the population is sick one week later, find a formula for the proportion of the popoulation that is sick at time $$t\text{.}$$
Solution.
The intuition behind the assumption here is that a disease can only spread if there are individuals who are susceptible to the infection. As fewer and fewer people are able to be infected, the disease spread should slow down. Since $$y$$ is proportion of the population that is sick, $$1-y$$ is the proportion who are not sick, and the differential equation is
\begin{equation*} \frac{dy}{dt} = k(1-y)\text{.} \end{equation*}
Though the context is quite different, the differential equation is identical to the differential equation for Newton's Law of Cooling, with $$A=1\text{.}$$ The solution is
\begin{equation*} y = 1 - Ce^{-kt}\text{.} \end{equation*}
The conditions $$y(0)=0.05$$ and $$y(1) = 0.1$$ yield $$C = 0.95$$ and $$k = -\ln\left(\frac{18}{19}\right) \approx 0.0541\text{,}$$ so the final function is
\begin{equation*} y = 1-.95e^{\ln\left(\frac{18}{19}\right)t}\text{.} \end{equation*}
Notice that this function approaches $$y=1$$ in the limit as $$t \to \infty\text{,}$$ and does not suffer from the non-physical behavior described in Example 8.4.4.
In Example 8.4.4, we assumed disease spread depends on the number of infected individuals. In Example 8.4.6, we assumed disease spread depends on the number of susceptible individuals who are able to become infected. In reality, we would expect many diseases to require the interaction of both infected and susceptible individuals in order to spread. One of the simplest ways to model this required interaction is to assume disease spread depends on the product of the proportions of infected and uninfected individuals. This assumption (regularly seen in the context of chemical reactions) is often called the law of mass action.

Suppose a disease spreads through a population at a rate proportional to the product of the number of infected and uninfected individuals. If 5% of the population is sick initially and 10% of the population is sick one week later, find a formula for the proportion of the population that is sick at time $$t\text{.}$$
Solution 1. Video solution
Solution 2.
The differential equation is
\begin{equation*} \frac{dy}{dt} = ky(1-y)\text{.} \end{equation*}
This is exactly the logistic equation with $$M = 1\text{.}$$ We solved this differential equation in Example 8.2.8, and found
\begin{equation*} y = \frac{1}{1 + be^{-kt}}\text{.} \end{equation*}
The conditions $$y(0)=0.05$$ and $$y(1) = 0.1$$ yield $$b = 19$$ and $$k = -\ln\left(\frac{9}{19}\right) \approx 0.7472\text{.}$$ The final function is
\begin{equation*} y = \frac{1}{1+19e^{\ln\left(\frac{9}{19}\right)t}}\text{.} \end{equation*}
Based on the three different assumptions about the rate of disease spread explored in the last three examples, we now have three different functions giving the proportion of a population that is sick at time $$t\text{.}$$ Each of the three functions meets the conditions $$y(0)=0.05$$ and $$y(1) = 0.1\text{.}$$ The three functions are shown in Figure 8.4.8.
Notice that the logistic function mimics specific parts of the functions from Examples 8.4.4 and Example 8.4.6. We see in Figure 8.4.8.(a) that the logistic and exponential functions are virtually indistinguishable for small $$t$$ values. When there are few infected individuals and lots of susceptible individuals, the spread of a disease is largely determined by the number of sick people. The logistic curve captures this feature, and is “almost exponential” early on.
In Figure 8.4.8.(b), we see that the logistic curve leaves the exponential curve from Example 8.4.4 and approaches the curve from Example 8.4.6. This result implies that when most of the population is sick, the spread of the disease is largely dependent on the number of susceptible individuals. Though there are much more sophisticated mathematical models describing the spread of infections, we could argue that the logistic model presented in this example is the “best” of the three.

### Subsection8.4.2Rate-in Rate-out Problems

One of the classic ways to build a mathematical model involves tracking the way the amount of something can change. We sometimes say these models are based on conservation laws. Consider a box with some amount of a specific type of material inside. (Some type of chemical, for example.) The amount of material of the specific type in the box can only change in four ways; we can add more to the box, we can remove some from the box, some of the material can change into material of a different type, or some other type of material can turn into the type we're tracking. In the examples that follow, we assume material doesn't change type, so we only need to keep track of material coming into the box and material leaving the box. To derive a differential equation, we track rates:
\begin{equation*} \text{ rate of change of some quantity } = \text{ rate in } - \text{ rate out }\text{.} \end{equation*}
Though we stick to relatively simple examples, this basic idea can be used to derive some very important differential equations in mathematics and physics.
The examples to follow involve tracking the amount of a chemical in solution. We assume liquid containing some chemical flows into a container at some rate. That liquid mixes instantaneously with the liquid already in the container. Then the liquid from the container flows out at some (potentially different) rate.

#### Example8.4.10.Equal Flow Rates.

Suppose a 10 liter tank has 5 liters of salt solution in it. The initial concentration of the salt solution is 1 gram per liter. A salt solution with concentration 3 gL flows into the tank at a rate of 2 Lmin. Suppose the salt solution mixes instantaneously with the solution already in the tank, and that the mixed solution from the tank flows out at a rate of 2 Lmin. Find a function that gives the amount of salt in the tank at time $$t\text{.}$$
Solution 1. Video solution
Solution 2.
We use the rate in - rate out setup described above. The quantity here is the amount (in grams) of salt in the tank at time $$t\text{.}$$ Let $$y$$ denote the amount of salt. In words, the differential equation is given by
\begin{equation*} \frac{dy}{dt} = \text{ rate in } - \text{ rate out }\text{.} \end{equation*}
Thinking in terms of units can help fill in the details of the differential equation. Since $$y$$ has units of grams, the left hand side of the equation has units g/min. Both terms on the right hand side must have these same units. Notice that the product of a concentration (with units g/L) and a flow rate (with units L/min) results in a quantity with units g/min. Both terms on the right hand side of the equation will include a concentration multiplied by a flow rate.
For the rate in, we multiply the inflow concentration by the rate that fluid is flowing into the bucket. This is $$\displaystyle \left(3 \frac{\text{g} }{\text{L} }\right)\left(2 \frac{\text{L} }{\text{ min } }\right) = 6$$ g/min.
The rate out is more complicated. The flow rate is still 2 Lmin, meaning that the overall volume of the fluid in the bucket is the constant 5 L. The salt concentration in the bucket is not constant though, meaning that the outflow concentration is not constant. In particular, the outflow concentration is not the constant 1 Lmin. This is simply the initial concentration. To find the concentration at any time, we need the amount of salt in the bucket at that time and the volume of liquid in the bucket at that time. The volume of liquid is the constant 5 L, and the amount of salt is given by the dependent variable $$y\text{.}$$ Thus, the outflow concentration is $$\displaystyle \frac{y}{5}$$ g/L, yielding a rate out given by
\begin{equation*} \left(\frac{y}{5}\frac{\text{ g } }{\text{ L } }\right)\left(2 \frac{\text{ L } }{\text{ min } }\right) = \frac{2y}{5}\text{ g/min }\text{.} \end{equation*}
The differential equation we wish to solve is given by
\begin{equation*} \frac{dy}{dt} = 6 - \frac{2y}{5}\text{.} \end{equation*}
To furnish an initial condition, we must convert the initial salt concentration into an initial amount of salt. This is $$\left(1\displaystyle \frac{\text{ g } }{\text{ L } }\right)(5 \text{ L } ) = 5$$ g, so $$y(0) = 5$$ is our initial condition.
Our differential equation is both separable and linear. We solve using separation of variables. The separated form of the differential equation is
\begin{equation*} \frac{5}{30 - 2y}\,dy = dt\text{.} \end{equation*}
Integration yields the implicit solution
\begin{equation*} -\frac{5}{2}\ln\abs{30 - 2y} = t+C\text{.} \end{equation*}
Solving for $$y$$ (and redefining the arbitrary constant $$C$$ as necessary) yields the explicit solution
\begin{equation*} y = 15 + Ce^{-\frac{2}{5}t}\text{.} \end{equation*}
The initial condition $$y(0) = 5$$ means that $$C = -10$$ so that
\begin{equation*} y = 15 - 10e^{-\frac{2}{5}t} \end{equation*}
is the particular solution to our initial value problem.
This function is plotted in Figure 8.4.11. Notice that in the limit as $$t\to\infty\text{,}$$ $$y$$ approaches $$15\text{.}$$ This corresponds to a bucket concentration of $$15/5 = 3$$ g/L. It should not be surprising that salt concentration inside the tank will move to match the inflow salt concentration.

#### Example8.4.12.Unequal Flow Rates.

Suppose the setup is identical to the setup in Example 8.4.10 except that now liquid flows out of the bucket at a rate of 1 L/min. Find a function that gives the amount of salt in the bucket at time $$t\text{.}$$ What is the salt concentration when the solution ceases to be valid?
Solution 1. Video solution
Solution 2.
Because the inflow and outflow rates no longer match, the volume of liquid in the bucket is not the constant 5 L. In general, we can find the volume of liquid via the equation
\begin{equation*} \text{ volume } = \text{ initial volume } + \text{ (inflow rate - outflow rate) } t\text{.} \end{equation*}
In this example, the volume at time $$t$$ is $$5 + t$$ liters. Because the total volume of the bucket is only 10 L, it follows that our solution will only be valid for $$0 \leq t \leq 5\text{.}$$ At that point it is no longer possible to have liquid flow into a the bucket at a rate of 2 L/min and out of the bucket at a rate of 1 L/min.
To update the differential equation, we must modify the rate out. Since the volume is $$5 + t\text{,}$$ the concentration at time $$t$$ is given by $$\frac{y}{5+t}$$ g/L. Thus for rate out, we must use $$\left( \frac{y}{5+t}\right)(1)$$ g/min. The initial value problem is
\begin{equation*} \frac{dy}{dt} = 6 - \frac{y}{5+t}, \text{ with } y(0)=5\text{.} \end{equation*}
Unlike Example 8.4.10, where we had equal flow rates, this differential equation is no longer separable. We must proceed with an integrating factor. Writing the differential equation in the form
\begin{equation*} \frac{dy}{dt} + \frac{1}{5+t}y = 6\text{,} \end{equation*}
we identify the integrating factor
\begin{equation*} \mu(t) = e^{\int \frac{1}{5+t}\,dt} = e^{\ln(5+t)} = 5+t\text{.} \end{equation*}
Then
\begin{equation*} \frac{d}{dt}\big((5+t)y\big) = 6(5+t)\text{,} \end{equation*}
yielding the implicit solution
\begin{equation*} (5+t)y = 30t + 3t^2 + C\text{.} \end{equation*}
The initial condition $$y(0) = 5$$ implies $$C = 25\text{,}$$ so the explicit solution to our initial value problem is given by
\begin{equation*} y = \frac{3t^2 + 30t + 25}{5+t}\text{.} \end{equation*}
This solution ceases to be valid at $$t=5\text{.}$$ At that time, there are 25 g of salt in the tank. The volume of liquid is 10 L, resulting in a salt concentration of $$2.5$$ g/L.
Differential equations are powerful tools that can be used to help describe the world around us. Though relatively simple in concept, the ideas of proportional change and matching rates can serve as building blocks in the development of more sophisticated mathematical models. As we saw in this section, some simple mathematical models can be solved analytically using the techniques developed in this chapter. Most sophisticated mathematical models don't allow for analytic solutions. Even so, there are an array of graphical and numerical techniques that can be used to analyze the model to make predictions and infer information about real world phenomena.

### Exercises8.4.3Exercises

#### Problems

##### Exercise Group.
In the following exercises, use the tools in the section to answer the questions presented.
###### 1.
Suppose the rate of change of $$y$$ with respect to $$x$$ is proportional to $$10 - y\text{.}$$ Write down and solve a differential equation for $$y\text{.}$$
###### 2.
A rumor is spreading through a middle school with 250 students. Suppose the rumor spreads at a rate proportional to the number of students who haven't heard the rumor yet. If 1 person starts the rumor, and 75 students have heard the rumor 3 days later, how many days will it take until 80% of the students in the school have heard the rumor?
###### 3.
A rumor is spreading through a middle school with 250 students. Suppose the rumor spreads at a rate proportional to the product of number of students who have heard the rumor and the number who haven't heard the rumor. If 1 person starts the rumor, and 75 students have heard the rumor 3 days later, how many days will it take until 80% of the students in the school have heard the rumor?
###### 4.
A feature of radioactive decay is that the amount of a radioactive substance decreases at a rate proportional to the current amount of the substance. The half life of a substance is the amount of time it takes for half of a given amount of substance to decay. The half life of carbon-14 is approximately 5730 years. If an ancient object has a carbon-14 amount that is 20% of the original amount, how old is the object?
###### 5.
Consider a chemical reaction where molecules of type A combine with molecules of type B to form molecules of type C. Suppose one molecule of type A combines with one molecule of type B to form one molecule of type C, and that type C is produced at a rate proportional the product of the remaining number of molecules of types A and B. Let $$x$$ denote moles of molecules of type $$C\text{.}$$ Find a function giving the number of moles of type C at time $$t$$ if there are originally $$a$$ moles of type A, $$b$$ moles of type B, and zero moles of type C.
###### 6.
Suppose an object with a temperature of 100$$^\circ$$ is introduced into a room with an ambient temperature of 70$$^\circ\text{.}$$ Suppose the temperature of the object changes at a rate proportional to the difference between the temperature of the object and the temperature of the room (Newton's Law of Cooling). If the object has cooled to 92$$^\circ$$ in 10 minutes, how long until the object has cooled to 84$$^\circ?$$
###### 7.
Suppose an object with a temperature of 100$$^\circ$$ is introduced into a room with an ambient temperature given by $$60 + 20e^{-\frac{1}{4}t}$$ degrees. Suppose the temperature of the object changes at a rate proportional to the difference between the temperature of the object and the temperature of the room (Newton's Law of Cooling). If the object is 80$$^\circ$$ after 20 minutes, find a formula giving the temperature of the object at time $$t\text{.}$$ (Note: This problem requires a numerical technique to solve for the unknown constants.)
###### 8.
A tank contains 5 gallons of salt solution with concentration 0.5 g/gal. Pure water flows into the tank at a rate of 1 gallon per minute. Salt solution flows out of the tank at a rate of 1 gallon per minute. (Assume instantaneous mixing.) Find the concentration of the salt solution at 10 minutes.
###### 9.
Dead leaves accumulate on the ground at a rate of 4 grams per square centimeter per year. The dead leaves on the ground decompose at a rate of 50% per year. Find a formula giving grams per square centimeter on the ground if there are no leaves on the ground at time $$t=0\text{.}$$
###### 10.
A pond initially contains 10 million gallons of fresh water. Water containing an undesirable chemical flows into the pond at a rate of 5 million gallons per year, and fluid from the pond flows out at the same rate. (Assume instantaneous mixing.) If the concentration (in grams per million gallons) of the incoming chemical varies periodically according to the expression $$2 + \sin(2t)\text{,}$$ find a formula giving the amount of chemical in the pond at time $$t\text{.}$$
###### 11.
A large tank contains 1 gallon of a salt solution with concentration 2 g/gal. A salt solution with concentration 1 g/gal flows into the tank at a rate of 4 gal/min. Salt solution flows out of the tank at a rate of 3 gal/min. (Assume instantaneous mixing.) Find the amount of salt in the tank at 10 minutes.
###### 12.
A stream flows into a pond containing 2 million gallons of fresh water at a rate of 1 million gallons per day. The stream flows out of the first pond and into a second pond containing 3 million gallons of fresh water. The stream then flows out of the second pond. Suppose the inflow and outflow rates are the same so that both ponds maintain their volumes. A factory upstream of the first pond starts polluting the stream. Directly below the factory, pollutant has a concentration of 55 grams per million gallons, and this concentration starts to flow into the first pond. Find the concentration of pollutant in the first and second ponds at 5 days.


text:
Question: Optimize the parameter span for loess (or spar for smooth.spline)
1
0
Entering edit mode
7.0 years ago
wenbo • 0

Hi,

Does anyone know well about the parameter optimization for loess or smooth.spline?

In function loess or smooth.spline, the parameter span (or spar for smooth.spline) is very important for the fitting. I have tried to use the following method to optimize the parameter spar for smooth.spline:

tuneSpline = function(x,y,span.vals=seq(0.1,1,by=0.05),fold=10){
mae <- numeric(length(span.vals))
fun.fit <- function(x,y,span) {smooth.spline(x = x,y = y,spar = span)}
fun.predict <- function(fit,x0) {predict(fit,x0)$y} ii = 0 for(span in span.vals){ ii <- ii+1 y.cv <- crossval(x,y,fun.fit,fun.predict,span=span,ngroup = fold)$cv.fit
fltr <- !is.nay.cv)
save(fltr,y.cv,y,file="tmp.rda")
mae[ii] <- mean(abs(y[fltr]-y.cv[fltr]))
}
span <- span.vals[which.min(mae)]
return(span)
}
require(graphics)
attach(cars)
tuneSpline(speed,dist,fold = length(dist))
## return 0.1

But the optimized spar by this method is always 0.1 (the minimum value in span.vals).

It's weird and I think the result may not be right.

Best regards!

XianWu

loess smooth.spline R • 5.2k views
0
Entering edit mode

Your code contains a couple of typos, namely missing argument 'y' on the third line, and missing opening bracket on the line with 'fltr' variable assignment. After fixing these, I ran the code and got 0.75 as the optimal value.

PS: I don't see how this question relates to bioinformatics, it's more suitable for StackOverflow

0
Entering edit mode

Pay attention to what you're doing. Why would you want to 'tune' the span of loess?

loess is used to make a line that doesnt exactly hit all the points; if you are measuring accuracy as how far away the points are from the line, then it follows that the optimal parameter is approaching zero. Now you've connected all the dots and made a zigzag. People use loess because they want a smooth curve that may miss points with assumed error, an optimal value is subjective simplicity; or maybe the 2nd derivative (curve sharpness)

1
Entering edit mode

It's a valid method of non-parametric estimation because of the use of cross-validation. See e.g. http://www.uab.ro/auajournal/upload/49_539_Nicoleta_Breaz-2.pdf for details.

0
Entering edit mode

if you run smooth.spline with the same data but without passing a spar parameter, is the fitted smoothing parameter that is returned by R less than 0.1?

Where did you get crossval from? The params for crossval::crossval are (predfun, X, Y, K, B, verbose, ...) so your ordering doesn't match that

0
Entering edit mode
7.0 years ago
russhh 5.6k

With a working implementation you're approach works fine.

tuneSpline = function(x,y,span.vals=seq(0.1,1,by=0.05),fold=10){
require(bootstrap)
fun.fit <- function(x,y,span) {smooth.spline(x = x,y = y,spar = span)}
fun.predict <- function(fit,x0) {predict(fit,x0)$y} mae <- sapply(span.vals, function(span){ y.cv <- bootstrap::crossval( x,y,fun.fit,fun.predict,span=span,ngroup = fold )$cv.fit
fltr <- which(!is.na(y.cv))
mean(abs(y[fltr]-y.cv[fltr]))
})
span.vals[which.min(mae)]
}

attach(cars)
tuneSpline(speed,dist,fold = length(dist))

# 0.75

0
Entering edit mode

Do you think this method is good?

0
Entering edit mode

When I used the code like below:
smooth.spline(speed,dist)\$spar

I got the value of spar is "0.7801305". It's very similar to the value of tuneSpline. It looks like that smooth.spline can do the optimization and select the best spar value for fitting.


text:
# In any metric space$(M,D)$, prove that $D(a_1,a_n)\leq D(a_1,a_2)+D(a_2,a_3)+\cdots+D(a_{n-1},a_n)$

In any metric space $$(M,D)$$, prove that $$D(a_1,a_n)\leq D(a_1,a_2)+D(a_2,a_3)+\cdots+D(a_{n-1},a_n)$$ for any $$a_1,a_2,a_3,\ldots,a_n \in M$$

how to we approach this problem is we prove by Mathematical Induction

• Just iterate the triangle inequality. – Francesco Polizzi Sep 6 '17 at 15:15
• @FrancescoPolizzi..sorry i did't get can you give me one more step – Inverse Problem Sep 6 '17 at 15:18

For $n=2$, it is trivial.
If it holds for a certain $n$, then\begin{align}D(a_1,a_{n+1})&\leqslant D(a_1,a_n)+D(a_n,a_{n+1})\\&\leqslant D(a_1,a_2)+D(a_2,a_3)+\cdots+D(a_{n-1},a_n)+D(a_n,a_{n+1}).\end{align}


text:
## Sunday, November 13, 2005

### Piotr Nowak's Homepage

Piotr Nowak

I was going to reference just a couple of Piotr's articles but then I thought that I might as well point to his entire home page. Everything is good here! In particular he shows that coarse embeddability into a Hilbert space (or into ell-one) is not the same as property A. The example is devastatingly simple: take the disjoint union of n-fold products of copies of some finite group (e.g. the group of order 2). Notice that the spaces here are quasi-isometric to cubes in R^n with the ell-one metric. If one took the ell-two (Euclidean) metric instead, wouldn't one get Yu's old counterexample to coarse Baum-Connes? Something interesting seems to be going on here.

[Of course these aren't bg spaces. Is there a bg space with the same property?]

## Monday, November 07, 2005

### [math/0511098] K-Theory of pseudodifferential operators with semi-periodic symbols

[math/0511098] K-Theory of pseudodifferential operators with semi-periodic symbols

Authors: Severino T. Melo, Cintia C. Silva
Subj-class: Operator Algebras; K-Theory and Homology
MSC-class: 46L80; 47G30

Let A denote the C*algebra of bounded operators on L2(R) generated by: (i) all multiplications a(M) by functions a\in C[-\infty,+\infty], (ii) all multiplications by 2\pi-periodic continuous functions and (iii) all Fourier multipliers F^{-1}b(M)F, where F denotes the Fourier transform and b is in C[-\infty,+\infty]. The Fredholm property for operators in A is governed by two symbols, the principal symbol \sigma and an operator-valued symbol \gamma. We give two proofs of the fact that K0(A) and K1(A) are isomorphic, respectively, to Z and Z\oplus Z: by computing the connecting mappings in the standard K-theory six-term exact sequences associated to \sigma and to \gamma. For the second computation, we prove that the image of \gamma is isomorphic to the direct sum of two copies of the crossed product of C[-\infty,+\infty] by an automorphism, and then use the Pimsner-Voiculescu exact sequence to compute its K-theory.


text:
# Double Integral - Polar Coordinates

1. Apr 13, 2009

### duki

1. The problem statement, all variables and given/known data

Evaluate by changing to polar coordinates

2. Relevant equations

Can't figure out how to make the integral stop after the sqrt(9-x^2)
$$\int_0^\frac{3}{\sqrt(2)} \int_x^{\sqrt(9-x^2)} e^-(x^2+y^2) dy dx$$

3. The attempt at a solution

I'm not sure where to really start on this one. I know it will end up being e^-r^2 but beyond that I'm not sure.

Last edited: Apr 14, 2009
2. Apr 14, 2009

### _Andreas

You'll have to express dxdy in other variables, and the intervals have to be changed.

3. Apr 14, 2009

### duki

How can I change them to polar coordinates?

Last edited: Apr 14, 2009
4. Apr 14, 2009

### _Andreas

First of all: Draw a figure in the xy-plane with to see what shape the domain yields (probably something like a circle sector). Then you should be able to figure out what values you should give $$r$$ and $$\phi$$. You usually substitute $$r*drd\phi$$ for $$dxdy$$ when using polar coordinates. However, the exact expression depends on what shape the domain yields.