text:
Select Board & Class

• Question 1
Answer each of the following questions briefly:                                                          [10 × 2 = 20 Marks]

(i) Define joint venture.
(ii) State the provisions of the Partnership Act, 1932, in the absence of a Partnership Deed regarding

(a) Interest on Partner’s Drawing
(b) Interest on advances made by a partner to the firm other than capital.

(iii) State the complete accounting treatment of hidden goodwill at the time of admission of a partner.
(iv) Why are assets revalued and liabilities reassessed when there is a change in profit sharing ratio amongst the partners?
(v) State two differences between dissolution of partnership and dissolution of firm.
(vi) Why is a memorandum balance sheet prepared at the time of dissolution of a partnership firm?
(vii) State two similarities between calls in arrear account and calls in advance account.
(viii) What is the accounting treatment when shares are issued to promoters for consideration other than cash?
(ix) Differentiate between Joint Venture account and JV with ..... account.
(x) Mention the name and explain the part of capital of a company which is called up only on its winding up. VIEW SOLUTION
• Question 2
 Brian and Derek entered into a joint venture agreement sharing profits and losses equally. Brian purchased 10,000 litres of oil @ Rs 40 per litre and incurred freight and insurance amounting to Rs 10,000. The goods were sent to Derek to be sold in the market. Derek incurred Rs 5,000 on duty and Rs 3,000 on godown rent. During transit, 100 litres were stolen against which Brian received an insurance claim of Rs 3,000. Derek took delivery of the remaining consignment and sold 7,000 litres @ Rs 50 per litre. [10 Marks]

Finally, Derek took over the closing stock for business use.

Assume a normal loss of 10 litres due to leakage and evaporation.

You are required to prepare the Joint Venture Account and Derek’s account in the books of Brian assuming both coventurers maintain all accounts.

Note: All calculations are to be made to the nearest rupee. VIEW SOLUTION
• Question 3
 The capital accounts of Adam and Batty stood at Rs 40,000 and Rs 30,000 respectively after the necessary adjustments in respect of the drawings and the net profit for the year ended 31st December 2011. It was subsequently ascertained that interest on capital and on drawings @ 5% per annum were not taken into account in arriving at the divisible profits for the year. [10 Marks]

The drawings of the partners had been: Adam – Rs 1,200 drawn at the end of each quarter and Batty – Rs 1,800 drawn at the end of each half year.

The net profit for the year amounted to Rs 20,000. The partners share profits and losses in the ratio of 3 : 2.

You are required to pass the necessary journal entries to rectify the lapse in accounting and also prepare the adjusted capital accounts of the partner. VIEW SOLUTION
• Question 4
Following is the Balance Sheet of John and Jimmy as on 31st December 2010:                                                 [10 Marks]
 Liabilities Amount Rs Assets Amount Rs John’s capital 50,000 Goodwill 6,000 Jimmy’s capital 35,000 Land and building 40,000 Reserve 6,000 Furniture 3,750 Creditors 25,000 Stock 25,000 Debtors 20,000 Investments 15,250 Bank 4,500 Cash 1,500 1,16,000 1,16,000

The partners shared profits and losses in the ratio of 2:1. From 1st January, 2011. They agreed to share profit and losses equally. For this purpose, the following particulars are provided:

(a) Land and building are to be appreciated by 25%.

(b) Furniture valued at Rs 3,250.

(c) Market value of stock is Rs 22,500.

(d) A provision for bad debts @ 5% is to be created on debtors.

(e) Goodwill is valued at Rs 15,000.

Show the revised Balance Sheet of the firm as on 1st January, 2011 along with appropriate ledger accounts as proper working notes. VIEW SOLUTION
• Question 5
Henry, Jacob and Jackson are partners in a firm. Their Balance Sheet as on 31st December 2011, stood as follows:                                [10 Marks]
 Liabilities Amount Rs Assets Amount Rs Henry’s capital 2,00,000 Plant and machinery 2,00,000 Jacob’s capital 1,50,000 Furniture and fixtures 25,000 Jackson’s capital 40,000 Stock 1,05,000 General reserve 1,00,000 Debtors 1,50,000 Creditors 1,00,000 Investments 1,20,000 5,90,000* 6,00,000*

The partnership deed provides that the representatives of the deceased partner shall be entitled to:

(a) Deceased partner’s capital as appearing in the last balance sheet.

(b) Interest on capital @ 6% per annum up to date of death.

(c) His share of profit up to date of death on the average of last three years’ divisible profit.

(d) His share of goodwill valued at two years’ purchase of the average divisible profit of last three years.

(e) His share of any undistributed profits and losses as per last drawn balance sheet.

(f) Interest on drawings up to date of death will be charged @ 10% per annum.

(g) Assets and liabilities of the firm on the date of death will be revalued and reassessed respectively by an independent valuer.

Jacob died on 30th June, 2012 and the valuer appointed by Henry and Jackson with the consent of the legal heirs of Jacob recommended as follows:

(i) Plant and Machinery to be depreciated by 5%.

(ii) Furniture and fixtures to be taken at Rs 20,000.

(iii) Stock to be reduced by 10%.

(iv) A provision of $2\frac{1}{2}%$ is to be raised against debtors for doubtful debts.

(v) The investments are to be valued at Rs 1,50,000.

The divisible profits for the last three years were Rs 6,50,000 Rs 6,40,000 and Rs 6,90,000.

Jacob’s drawings up to the date of death amounted to Rs 1,00,000.

Finally, it was decided to transfer the amount due, to Jacob’s executor’s loan account.

You are required to prepare the revaluation account, partners’ capital accounts and the balance sheet.

Note: All calculations are to be made to the nearest rupee.

*The total of Balance Sheet given in the question does not match. VIEW SOLUTION
• Question 6
 Mathew, Clarke and Adolf are partners sharing profits and losses in the proportion to their capitals, which on 31st December 2011 stood at Rs 3,00,000, Rs 2,00,000 and Rs 1,00,000 respectively. The firm’s liabilities on that date amounted to Rs 3,00,000 apart from a contingent liability of Rs 60,000 not so far brought into the books, which also matured for payment. In addition, Adolf had loaned Rs 80,000 to the firm on which he was entitled to receive interest on loan @ 6% per annum for the whole year. [10 Marks]

They dissolved the partnership on 31st December, 2011 and the assets realized Rs 14,40,000.

You are required to close the books of the firm.

Note: All calculations are to be made to the nearest rupee. VIEW SOLUTION
• Question 7
Norton and Company Limited make an issue of 10,000 equity shares of Rs10 each payable as follows:                         [10 Marks]
Rs 2 on application,
Rs 3 on allotment and
Rs 5 on first and final call (3 months after allotment).
Applications were received for 12,000 shares and the directors refunded the excess application money. One shareholder who was allotted 20 shares paid first and final call with allotment money and another shareholder did not pay allotment money on his 30 shares but which he paid with first and final call. Directors have decided to charge and allow interest, as the case may be, on calls in arrear and calls in advance respectively according to the provisions of Table-A of the Companies Act 1956. Journalise the above transactions in the books of the company. VIEW SOLUTION
• Question 8
Parker and Company Limited issued 2,000 15% debentures of Rs 100 each at a premium of 10% on 1st January, 2011.  [10 Marks]
Under the terms of issue:
(a) Entire money is payable on application.
(b) Debenture interest is payable half yearly on 30th June and 31st December.
(c) Tax to be deducted at source @ 10%.
(d) Debentures are to be redeemed after 5 years from the date of issue.
Pass the necessary journal entries for the year 2011. VIEW SOLUTION
• Question 9
(a) What is the main object of preparing a Comparative Balance Sheet?                                        [10 Marks]
(b) From the following information, prepare a Comparative Balance Sheet of Relay Ltd.
 Particulars 31st March 2012 (Rs) 31st March 2013 (Rs) Equity Share Capital 25,00,000 26,00,000 Fixed Assets 30,00,000 35,00,000 Reserve & Surplus 5,00,000 6,00,000 Investments 5,00,000 5,00,000 Long-Term Loans 15,00,000 14,00,000 Current Assets 15,00,000 11,50,000 Current Liabilities 5,00,000 5,50,000
VIEW SOLUTION
• Question 10
(a) The following information is available from the books of Arnold and Company Limited :                               [10 Marks]

Debtors turnover ratio = 4 times

Cost of goods sold = Rs 6,40,000

Gross profit = 20% on sales

Closing debtors were Rs 20,000 more than at the beginning.

Cash sales being $33\frac{1}{3}%$ of credit sales

From the above calculate the opening debtors and the closing debtors of the company.

(b) The following information is available from the books of Duncan and Company Limited:

The above company has a current ratio of 4.5:1, quick ratio of 3:1 and its inventory is Rs 36,000.

From the above calculate the current assets, current liabilities and quick assets of the company.

(c) Give the formulae for computing:

(i) Working Capital Turnover Ratio.

(ii) Earnings per Share
VIEW SOLUTION
• Question 11
(a) Define ‘Operating Activities’.                                                                                [10 Marks]
(b) From the following Balance Sheets of Pixie Ltd. As on 31st March, 2011 and 31st March 2012, prepare a Cash Flow Statement.  Particulars 31.03.2011 (Rs) 31.03.2012 (Rs) I. Equity and Liabilities 1. Shareholders’ Funds Equity Share Capital 3,00,000 6,50,000 10% Preference Share Capital 50,000 1,00,000 2. Reserves and Surplus 31.03.2011 31.03.2012 Balance of Statement of Profit & Loss 1,60,000 1,10,000 General Reserve 90,000 60,000 Securities Premium Reserve 30,000 Preliminary Expenses (adjusted 31.03.2011) (30,000) - 2,50,000 1,70,000 2,50,000 1,70,000 3. Non Current Liabilities Long Term Borrowings 10% Debentures 3,50,000 2,50,000 Total 9,50,000 11,70,000 II. Assets 1. Non Current Assets Fixed Assets 4,50,000 7,00,000 Non Current Investments 50,000 60,000 2. Current Assets Inventories 2,00,000 2,10,000 Trade Receivables 1,50,000 90,000 Bank 60,000 1,10,000 Short term Investments 40,000 - 9,50,000 11,70,000


text:
# Condensing code that generates Pascal's triangle

I recently started learning Java for a class and my teacher gave us an assignment in which we had to write up code which would print out the Pascal's triangle to an amount of rows decided by the user, and use recursion to do so. I believe that I'm done with the assignment, but wanted to know, for myself, as to how I could improve and condense this messy code (the array complicates things but I wanted to use it for a different program that expands polynomials ($(x+b)^n)$).

import java.io.*;
import java.util.*;

public class PascalTriangleYar
{
private static int[][] xArr;
private static int g =2;

public void printArray(int[][] xArray)
{

for(int r=0; r<xArray.length; r++){
System.out.println("");
for(int c=0; c<xArray[r].length; c++)
if(xArray[r][c]==0)
System.out.print("\t");
else
System.out.print(xArray[r][c]+"\t");}

}

public int[][] getTri()
{
return xArr;}

public void pTriangle(int r)
{
int n=r;
xArr = new int[r][2*r-1];
xArr[0][r-1]=(1);
p2T(r, 1);
printArray(xArr);
}

private void p2T(int r, int n)
{
int z=0;

int p=r-g;

xArr[n][p]=(1);

for(int fd=0; fd<xArr[0].length-1; fd++){
if(fd==0)
xArr[n][fd]= xArr[n-1][0]+xArr[n-1][1];
else
xArr[n][fd]= xArr[n-1][fd-1] + xArr[n-1][fd+1];

xArr[r-1][2*r-2]=1;

}

g++;
if(n<r-1)
{
p2T(r,n+1);
}
// else
// {return;}

}

public static void main(String [] args)
{
PascalTriangleYar tri = new PascalTriangleYar();
Scanner inputReader = new Scanner(System.in);
System.out.println("Enter a number (x). A pascal's triangle of x rows will be printed.");
int x = inputReader.nextInt();
tri.pTriangle(x);
}
}

## 3 Answers

### Bugs

The variables xArr and g shouldn't be static. The consequence of them being static is that you cannot use this class twice, because the static state is not reset per instance. For example this will cause an ArrayIndexOutOfBoundsException:

new PascalTriangleYar().pTriangle(3);
new PascalTriangleYar().pTriangle(4);

You can fix that by making g non-static. But you should also make xArr non-static too, because quite simply, it doesn't need to be static, and there's no reason whatsoever to make it static.

### Condensing the code

Condense code doesn't sound great. It makes me imagine code with no vertical spaces and no spacing around operators. That's condense. And that's no good. Maybe you're looking for a different term. Maybe want to DRY this up, reducing duplication, and increasing reusability and modularity.

There's one thing useful to do for "condensing", is removing unnecessary elements:

• The getTri method is unused
• The n variable in pTriangle is unused
• The z variable in p2T is unused

Another thing for condensing is removing some excessive vertical space. That is, one blank line between methods is enough, and there shouldn't be blank lines before the closing braces } of code blocks.

### Code duplication

Look very suspiciously at code like this:

xArr[n][p] = 1;

for (int fd = 0; fd < xArr[0].length - 1; fd++) {
if (fd == 0)
xArr[n][fd] = xArr[n - 1][0] + xArr[n - 1][1];
else
xArr[n][fd] = xArr[n - 1][fd - 1] + xArr[n - 1][fd + 1];

xArr[r - 1][2 * r - 2] = 1;
}

Notice the duplication in the if-else branches. Something is fishy there. What's so special about the fd == 0 case? On closer look, the case of fd == 0 is already taken care of, by the xArr[n][p] = 1; statement earlier. You can change the initialization step of the for loop to int fd = 1, and the if-else can go away:

for (int fd = 1; fd < xArr[0].length - 1; fd++) {
xArr[n][fd] = xArr[n - 1][fd - 1] + xArr[n - 1][fd + 1];
xArr[r - 1][2 * r - 2] = 1;
}

### Coding style

As @Hosch already covered many coding style issues I shouldn't repeat that, but they are actually so important that I want to reemphasize: please do everything that he suggested, it will make a huge difference in the readability of your code. Note that you don't actually have to manually make those corrections by yourself, any decent IDE (Eclipse, Netbeans, IntelliJ) has shortcuts to do at least most of it for you at the touch of a few keystrokes.

In addition, prefer to use for-each loops instead of counting loops whenever possible. For example printArray can be rewritten as:

public void printArray(int[][] xArray) {
for (int[] row : xArray) {
System.out.println();
for (int item : row) {
if (item != 0) {
System.out.print(item);
}
System.out.print("\t");
}
}
}

Notice some other improvements there:

• Flipped the item == 0 condition to avoid duplicating System.out.print("\t")
• No need for the "" in System.out.println("")

### Thread safety, robustness

The code as it is, is very fragile. This is because of the member fields g and xArr. These fields give instance of your class a state, and if the pTriangle method gets called by multiple threads at the same time, they can break each other.

It's ok to have state and have thread-unsafe code when necessary. But in this program it's not necessary. You can completely eliminate the g and xArr member fields, and pass them around as parameters to the methods that need them. In fact, you don't need g at all, because its value is always n + 1, so you can always derive it from n.

With these tips, the code can be rewritten as:

public void pTriangle(int r) {
int[][] xArr = new int[r][2 * r - 1];
xArr[0][r - 1] = 1;
p2T(xArr, r, 1);
printArray(xArr);
}

private void p2T(int[][] xArr, int r, int n) {
int p = r - n - 1;

xArr[n][p] = 1;

for (int fd = 1; fd < xArr[0].length - 1; fd++) {
xArr[n][fd] = xArr[n - 1][fd - 1] + xArr[n - 1][fd + 1];
xArr[r - 1][2 * r - 2] = 1;
}

if (n < r - 1) {
p2T(xArr, r, n + 1);
}
}

There is a lot that can be improved in this code. First and foremost - please use longer, descriptive variable names - p doesn't really tell you anything. The only time I would say it is acceptable to use a single-letter variable name is the traditional i and c variables used like this:

for (int i = 0; i < val; i++)
for (char c : string)

Second, please indent your code following the standard indentation levels of (usually) 4 spaces per indent level, with the inside of classes, methods, loops, if statements, and a few other instances adding one indentation level.

Third, be consistent with your styles. Right here, you use braces around a one-statement if block:

if(n<r-1)
{
p2T(r,n+1);
}

And here, you do not:

if(fd==0)
xArr[n][fd]= xArr[n-1][0]+xArr[n-1][1];

I recommend you always use braces - this applies to loops too.

Fourth, you should use spaces around operators:

if(fd == 0)

Fifth, again use consistent styling, and do not wrap braces around content like this:

public int[][] getTri()
{
return xArr;}

That should be like this:

public int[][] getTri()
{
return xArr;
}

Traditionally, you use i and j for nested for loops:

  for(int r=0; r<xArray.length; r++){
System.out.println("");
for(int c=0; c<xArray[r].length; c++)
if(xArray[r][c]==0)
System.out.print("\t");
else
System.out.print(xArray[r][c]+"\t");}

Also, use the correct indentation, fix your braces, and you should add braces to your if/else block like this:

if (condition) {
// if statements...
} else {
// else statements...
}

This follows standard Java brace formatting, although some programmers place the else on a separate line.

I am sure your code can be improved in its execution as well, but these are more pressing issues for now - make your code easy to read, and you will catch more bugs and be able to improve it on your own, as well as getting reviews on content instead of style.

I think you may have slightly misunderstood the assignment given to you: the point is to print the triangle recursively, i.e. print each line of the triangle as it is calculated, without keeping any state (state management is a major concern in recursive algorithms).

In your case, you should apply the recursion on the rows of the triangle, as a row should be constructed thanks to the previous row.

import java.util.Arrays;
import java.util.Scanner;

public class PascalTriangle {

public static void main(String[] args) {
System.out.println("Enter a positive integer (x). A Pascal's triangle of x rows will be printed.");
int numRows = new Scanner(System.in).nextInt();
new PascalTriangle().generate(numRows);
}

public int[] generate(int numRows) {
int[] result = new int[numRows];
result[0] = 1;
if (numRows > 1) {
int[] previousRow = generate(numRows - 1);
for (int ii = 1; ii < numRows - 1; ii++) {
result[ii] = previousRow[ii - 1] + previousRow[ii];
}
result[numRows - 1] = 1;
}
System.out.println(Arrays.toString(result));
return result;
}
}

This code is probably acceptable as a solution to the problem you have provided. From a professional point of view, it is still not satisfactory, because the recursive function mixes two concerns (calculating the line and printing it). One should thus refactor it by passing a consumer to be applied on the intermediate result (but that would be off-topic here).

Others have made quite useful comments regarding your code. If you like, spend some time and read about Kent Beck's four rules of simple design. In my opinion, these 4 rules are essential to write good code.

format: plain


text:
# Machine Learning with Missing Labels Part 3: Experiments

In this series of posts we look at Transductive and SemiSupervised Learning–an old problem, a hard problem, and a fundamental problem Machine Learning.  Unlike Deep Learning or large scale ML,

We want to learn as much as we can from as labeled little data as possible.

We focus on text classification.  Why?

1. The feature space is simple — its just words.
2. With the true labels, a simple SVM gives near perfect accuracy.
3. Text satisfies the cluster assumption.

Why isn’t this done all the time?

We can generate good (not great) Semi Supervised text classifiers.   But

1. creating the input data is hard.
2. setting the input parameters is harder.
3. we can’t always distinguish the good solutions from the bad.

The 1st post looked at (1); here we try to understand (2&3), and look for simple, practical heuristics to make these old methods useful.

We can think of the TSVM/S3VM as generating several potentially good labelings on the unlabeled data. To solve (3), we need to find the best labeling–which means judging the label and/or classifier quality, such as the label entropy , cluster overlap, etc.

Or, alternatively, we might try to average the good solutions, similar to the way Hinton et. al. have recently suggested averaging an ensemble of models to take advantage of Dark Knowledge.

Thanks to Matt Wescott for pointing out this PDF and discussions on it.

To explore this, we run experiments using some old, existing, open source Transductive SVM (TSVM) and SemiSupervised SVM (S3VM) codes:

Our work is guided by  the results in this 2014 paper on the QN-S3VM method, as applied to text data.

We thank Fabian Gieseke for help in reproducing and understanding these results.

For the TSVM, some available codes and algorithms are

• SvmLight:  Graph Cutting Algo
• SvmLin:  MultiSwitch (MS-TSVM) and Deterministic Annealing (DA-TSVM)
• UniverSvm: Convex Concave Continuation Procedure (CCCP)
• QN-S3VM: Quasi Newton SemiSupervised SVM

We can also compare the results to a SVM baseline, using either

All these codes are Unix standalone C programs except QN-S3VM and Scikit-Learn, which are Python.

We examine SvmLin and its MultiSwitch (MS-TSVM) method.

SvmLin is the TSVM benchmark for most studies.  After we work this up, we will move on to other codes listed. I also would like to test other TSVM/S3VM methods, such as S3VM-MIP, S4VM, S3VMpath, and many others, but may are MatLab codes and  I don’t have C or Python open source code readily available.  Or really the time 😛

We do not consider cases of weakly-supervised learning, where the labels may be both missing and/or have errors… but let me point out  a 2013 paper on the WellSVM method.  It also compares the above methods and is worth a read.

I hope this post gives some flavor to what is a very complicated and fundamental problem in machine learning.  (And maybe take some ideas from Deep Learning to help solve the TSVM problem as well)

### Methods: The real-sim Data Sets:

We care about text classification. To this end, we reproduce the performance of SvmLin, and, later,  other methods, on the real-sim text dataset (listed in Table 2 in the paper).  The real-sim dataset was used in the original SvmLin paper; it is an accepted baseline for these methods.

This data set consists of  72309 labeled documents: 22238 (+1) and 50071 (-1).

The fraction of positively labeled documents $R^{+}_{true}=30.75%$.

#### Creating the Labeled, Unlabeled, and Holdout Sets:

I have created an IPython Notebook (make_realsim_inputs.ipynb) which can read the real-sim data and generate the input files for the various C programs listed above: SvmLight, SvmLin, & UniverSvm.

We can see it in the NBViewer here

The real-sim dataset is split in half, and 3 data sets are created.   Half is used to train TSVM (labeled L and unlabeled U); the rest is a holdout set (HO) for testing.

Following Table 2, the notebook generates:

• labeled (L) of sizes roughly: l=90, 180, 361, 1486, & 2892
• an unlabeled set (U) of size u=36154-l.
• a test or HoldOut set HO (of the remaining data)

Each data set (L,U,HO) also has ~0.31 fraction of labeled examples; U and HO are statistical replica’s of L, albeit larger.

The input files consist of a training file (or 2 files for SvmLin) and 3 test files (6 forSvmLin): labeled L, unlabeled U, and holdout HO.   They are in the SvmLight format.

I.e. the SvmLin input files, for l=90,  are:

filename                                          size (lines)                                   purpose

svmlin.train.90.examples            36154                 labeled + unlabeled  train tsvm

svmlin.train.90.labels                   36154

svmlin.testL.90.examples                 90                 train labeled baseline

svmlin.testL.90.labels                        90

svmlin.testU.90.examples            36154                evaluate unlabeled set

svmlin.testU.90.labels                   36154

svmlin.testHO.90.examples         36155                evaluate holdout set

svmlin.testHO.90.labels                36155

#### Grid Searches with gnu parallel

Astoundingly, rather than performing a full grid search, many research papers fix the regularization parameters, guess them using some crude Bayesian scheme, or attempt to transfer them from some other data set. This makes it really hard to evaluate these methods.

We use a ruby script and the gnu_parallel program to run the command line unix programs and grid search the parameters. The script also computes the final HoldOut accuracy and metrics such as the margin and label entropy.

svmlin.rb

Gnu parallel lets us easily grid search the regularization parameters by running the TSVM codes in parallel.

We do a broad grid search

$W\in[.0001,0.001,0.01,0.1,1,10,100,1000,10000]$

$U\in[.0001,0.001,0.01,0.1,1,10,100,1000,10000]$

$R\in[0.25, 0.26, 0.27,\cdots,0.35,0.36,0.37]$

by creating a directory for each run

parallel "mkdir A2W{1}U{2}R{R}" ::: .0001 0.001 0.01 0.1 1 ::: 1 10 100 1000 1000 ::: 0.28 0.29 0.31 0.32 0.33 0.34

and then running SvmLin in each directory, simultaneously

parallel "cd A2W{1}U{2}R{R}; \$SVMLIN -A 2 -W {1} -U {2} -R {3} ../svmlin.train.examples.90 ../svmlin.train.labels.90 > /dev/null"  ::: 0.0001 0.001 0.01 0.1 1  :::  1 10 100 1000 10000 ::: 0.28 0.29 0.31 0.32 0.33 0.34

We can then evaluate each run on the U or HO data set.  We will find the optimal W and U are in the range of the original crude estimates W=0.001, U=1, and R=0.31

How can we evaluate the accuracy of our TSVM, here, and in a real world setting?

#### Ground Truth

Since we know the labels on both the U and the HO sets , these are a ground truth from which we can evaluate how well the best model(s) perform.  We can get an upper bound on the best possible Generalization Accuracy (on the HO set) by training an SVM on L+U using the true labels, and then applying this model to HO.

The best expected HO accuracy here is ~ 97 %

Also, note this is different from the Reconstruction Accuracy on HO, which is > 99 %.

We might also obtain a better generalization accuracy with different features, such as applying GloVe or even unsupervised pre-training on L+U.  We examine this in a future blog.   We are, in particular, interesting in comparing the Deep Learning Auto-Encoders with Convex NMF, including recent variants applied to document clustering.

#### Baseline

We need a baseline for comparison.  The IPython Notebook computes a baseline accuracy for the labeled data set (L); this can also be done with LibLinear or even SvmLin (using -A 1).

We then run the small L model on the HoldOut (HO) set for each l=90,180,…,  yielding baseline accuracies of

 split size size of L (l) HO Accuracy 0.0025 90 85 % 0.005 180 87.5 % 0.001 361 90 % 0.004 1446 93 % 0.008 2892 94 %

please note that these are computed from 1 random sample, and may be slightly different (by ~1%) for each run. Also, that the command line and scikit-learn liblinear have different defaults; we use C=10,fit_intercept=False.

#### Finding the Best Accuracy:

We are generating a large number of nearly equivalent models, parameterized by

$[\Gamma_{L}(U,W,R^{+})]$

The inputs are related to the objective function in blog post 1.

$W=\gamma$, $U=\gamma'$,  and $r=0.31$

Every useful model will have the same reconstruction accuracy on the labeled examples L, and every model proposes a different soft labeling for the unlabeled examples U.

How can we compare different models $\Gamma_{L}(U,W,R^{+})$?

Essentially, we use a margin method to guess good labelings of the data, but we need an unsupervised heuristic to select the optimal labeling.   Can we simply apply Cross-Validation to the small labeled set L?  Or Leave One Out CV (LOO-CV) ?  What filters can we apply to speed up the calculations ?

##### Best Accuracy on the Labeled Set

SvmLin may produce inferior or even nonsense models.  But more subtly,  some models may even have a very high training  (on U), and a very high test accuracy (on HO), but a very low accuracy on L.  These are not useful  because  in the real world, we don’t know the labels on U or HO.

We always want to first filter the possible  solutions by selecting those with the best accuracy on the L.

##### Filter by Final Objective Function  (FOF)

Since we are minimizing the objective function, we only consider solutions with FOF < 0.01.  Note this is very different than simply assuming the best solutions has absolute minimum FOF across all input parameters.

We discard all solutions with Final Objective Function (FOF) > 0.01

For l=180, for example, this reduces the set of possible solutions from 1430 to 143.

##### Maximum Margin Solution…NOT

Wait, can’t we just take the solution with the maximum margin (or 1/norm)

$m=\dfrac{1}{\sum_{i}w_{i}^{2}}$

No. Think about how we practice supervised learning; we train a model, and set the regularization parameters by cross-validation.  In the TSVM and SSL methods, we can can also apply CV (or LOO-CV), but only to the labeled set L.

The maximum margin solution is only best for a given set of input / regularization parameters (U,W,R). Every model $\Gamma_{L}(U,W,R^{+})$ induces a different labeling on U  (that is, they form an equivalence class on L, not L+U).    In fact, the best overall solution has the minimum margin amongst a broad scan of (U,W).

where the output weights $w_{i}$ are taken from

svmlin.training.examples.90.weights

##### Optimal Parameters for the HoldOut Test Accuracy

(this section is still under construction)

##### Cross Validation and Leave One Out on the Labeled Data

As with a standard SVM, one can try to apply Cross Validation (CV) to the labeled set L to select the best TSVM model.  Most academic studies run 5-fold CV on the L set.  This is harder, however, because

1. when L is small, the i.i.d. assumption fails, so CV my give spurious results
2. we really should use Leave One Out Cross Validation (LOO-CV), but this increases the run time significantly
3. the SvmLin code does not include CV or LOO-CV
4. the SvmLin DA-TSVM is unstable and I had to switch to MS-TSVM to complete this
5. my laptop cant take any more over clocking so I had to pause this for bit

I will finish this section once I either

1. modify SvmLin to run CV / LOO-CV
2. modify and use UniverSvm and the CCCP method, which is an order of magnitude faster than TSVM
3. and/or get this all working in IPython+Star Cluster so I can run LOO-CV at scale
##### Minimum Entropy of the Soft Labels

The SvmLin DA algo minimizes the entropy on unlabeled examples $S_{u}$ (it is the key stopping criteria, sec 3.2.3).  Perhaps the model with minimum $S_{u}$ generalizes best?

This is the essence of Entropy Regularization--a common component of many Semi Supervised Learning formulations.

We can evaluate the proposed soft labels $\mu_{u}$ of the unlabeled set U, found in

svmlin.testU.examples.90.outputs

We convert soft labels to a probability $p_{u}$:

$p_{u}=\dfrac{{\dfrac{{1}}{1+exp(-\mu_{u})}}}{\sum\dfrac{{1}}{1+exp(-\mu_{u})}}$

and compute the Entropy on U

$S_{u}=-\sum_{u}(p_{u}ln(p_{u})+(1-p_{u})ln(1-p_{u}))$

We hope that TSVM solutions with minimum $S_{u}$ will consistently yield a very good Generalization Accuracy (on the HO set) across a grid of search (U,W,R)–and preliminary results confirm this.

Let’s look at the l=90 case, and plot first the HO accuracy vs the Label Entropy $S_u$.

(Recall we only take solutions with FOF > 0.01 and the best training accuracy on the true labeled set.)

We see at 3-4 distinct sets of solutions with nearly equivalent entropy across a wide range of HO accuracy, and 2 classes include improved solutions (HO Accuracy > baseline 85%)

We call these Equivalence Classes under the Label Entropy.

Other solutions also show that the minimum Entropy solution is the best solution–for a fixed $R^{+}_{in}$:

We select the minimum Entropy class of solutions.

Notice that the l=90 case is greatly improved above the 85% baseline, whereas l=1446 shows only a slight (0.5%) improvement–and 2-3% less than the best expected accuracy of 97%. We see the same results in the QN-S3VM and WellSVM papers, and suggests that

Transductive and SSL Learning may be limited to small labelled sets

where the percentage of labeled data is $L\sim 10-15%$ of U.

##### Predicted Fraction of Positive Examples

Recall we have to input an estimate $R^{+}_{in}$ of the fraction of positive labels on U $R^{+}_{U}$.

We assume we estimate $R^{+}_{U}$ to within 10% using about 100 examples ($l\sim O(100)$)

We would prefer a high quality estimate if possible because the final, predicted $\hat{R}^{+}_{U}$  and $\hat{R}^{+}_{HO}$ appears to depend strongly on $R^{+}_{in}$.

Here we test varying the input $R^{+}_{in}$.  We expect the predicted $\hat{R}^{+}_{HO}$ to be correlated with the generalization accuracies, and preliminary results also confirm this (note that all plots show the predicted fraction $\hat{R}^{+}_{HO}$):

The predicted fraction $\hat{R}^{+}_{HO}$ also forms Equivalence Classes $\Gamma_{L,S}(R^{+})$ under the Entropy $S_{U}$.

Of course, we know the true $R^{+}_{HO}=0.31$, so the minimum Entropy solution is not the absolute best solution.

Perhaps a more generalized form of the Entropy would be more discerning?   We would prefer a python toolbox like this one and need a way to fit the parameters.

We might also try to improve the TSVM search algorithm, as in the S4VM: Safe Semi-Supervised SVM methods.  The S4VM tries to improve upon the SvmLin DA-TSM algo using Simulated Annealing, and then selects the best solutions by evaluating the final cluster quality.  This looks promising for simple applications.  Indeed, one might even try to implement it in python using the recent basinhopping library.

##### Transduction and the VC Theory

We have said that the VC Theory is a really theory about Transductive Learning.

We see now that to apply the TSVM in practice, the unlabeled data set U really needs to be an accurate statistical replica, as in the VC Statistical Learning Theory for Transduction.

We have tested cases where we have a good replica, but we did not estimate$R^{+}_{U}$ well; we have not yet tested cases where the U  is NOT a good replica and we can only estimate $R^{+}_{U}$ partially.  This needs to be done.

In the literature this is called using class proportions, and some recent estimatation methods have been proposed (and here)–although the QN-S3VM papers do not attempt this.  Recently Belkin has shown how to estimate this fraction using methods of traditional integral methods.

The TSVM accuracy may depends on how well one can estimate the fraction (r) of positively labeled examples.

Also, we presume that TSVM models overtrain, and are biased towards either the (+) or (-) class.

For l=1446, we find a single class of minimum Entropy entropy solutions

with $S\approxeq-5.467$, W=0.001, U=1 and $\hat{R}^{+}_{HO}\in[0.25,0.37]$.

They all have a high HO Accuracy–but may be biased towards choosing (+) labels because the minimum S solution has $\hat{R}^{+}_{HO}=0.36$, not 0.31.

If we can’t estimate the $R^{+}_{U}$ well, may be able to average of the minimum Entropy solutions, thereby canceling out the biases in the over-trained models (i.e. average all $\hat{R}^{+}_{U}\in[0.28\cdots 0.34]$ TSVM models)

This is what Dark Knowledge, is all about–creating a simpler model by ensemble averaging– and we hope these recent advances in Deep Learning can help with Transductive Learning as well.

It is noted that the recent WellSVM method also addresses this problem.  WellSVM uses a convex relaxation of the TSVM problem to obtain a min max optimization over the set of possible models allowed within a range of $R^{+}_{U}$  ; this is quite clever!

In a future blog, we will examine how the current TSVMs perform when tuning their parameters to obtain the best predicted fraction. If this is sound, in a future post, we will examine how to estimate the class proportions for text data.

#### Discussion

to come soon..stay tuned

#### Appendix

Each is TSVM is trained with a linear kernel.      The regularization parameters are adjusted to give both optimal performance on the initial training set (L), and best reconstruction accuracy on the (U) set.

Each program requires slightly different command line options for these.  There are also tuning parameters for each solver, and is necessary to set the tolerances low enough so the solvers can converge.  For example, even for a linear SVM, the primal solvers may not converge as rapidly as the dual solver, and can even give different results on the same data set (despite Von Neumann’s minimax theorem). And the default for sckit-learn LinearSVC has the Bias on, whereas LibLinear has the Bias off.  So be careful.

Below we show examples of training each the TSVMs on the labeled set (L), and evaluating the accuracy on a HoldOut set (HO), for l=90.  We show typical values of the regularization parameters, but these do need to be tuned separately.  We also show how to run the popular Liblinear program as a baseline (which uses the svmlight format); the paper uses LibSVM.

#### Baseline Linear SVM:

liblinear  -C 0.1  -v 5  svmlight.testL.90

#### MS-SvmLin:

svmlin  -A 2  -W 0.001 -U 1 -R 0.31   svmlin.train.examples.90 svmlight.train.labels.90

svmlin  -f   svmlin.train.examples.90.weights svmlight.testHO.examples.90 svmlight.testHO.labels.90

#### SvmLin DA:

svmlin  -A 3  -W 0.001 -U 1 -R 0.31    svmlin.train.examples.90 svmlight.train.labels.90

svmlin  -f   svmlin.train.examples.90.weights svmlin.testHO.examples.90 svmlin.testHO.labels.90

#### SvmLight Graph Cuts:

svm_learn -p 0.31 svmlight.train.90  svmlight.model.90

svm_classify  -C 100  svmlight.testHO.90  svmlight.model.90   svmlight.outHO.90

#### UniverSvm CCCP TSVM w/ramp loss:

universvm -C 1 -c 1 -s -0.5 -z 1 -o 1 -T universvm.testHO.90 universvm.train.90


text:
# Network Invariants for Real-time Systems

 Title Network Invariants for Real-time Systems Publication Type Conference Paper Year of Publication 2004 Authors Grinchtein, O, Leucker, M Conference Name 5th International Workshop on Verification of Infinite-State Systems Series Electronic Notes in Theoretical Computer Science Volume 98 Publisher Elsevier Science Publishers URL http://www.sciencedirect.com/
Bibtex:
```@inproceedings {GrinchteinL03,
title = {Network Invariants for Real-time Systems},
booktitle = {5th International Workshop on Verification of Infinite-State Systems},
series = {Electronic Notes in Theoretical Computer Science},
volume = {98},
year = {2004},
pages = {57{\textendash}74},
publisher = {Elsevier Science Publishers},
organization = {Elsevier Science Publishers},
url = {http://www.sciencedirect.com/},
author = {Olga Grinchtein and Martin Leucker}
}```
PDF:
Postscript:


text:
# Single-spaced comments in changes package with double-spaced document

I'm using the changes package for comments. Is it possible to get the comments to be single-spaced, even if the document itself is double-spaced?

MWE:

\documentclass{article}
\usepackage{changes}
\usepackage{lipsum}

\begin{document}

\lipsum[1-1][1-3]\comment{I would like this comment to be single-spaced.} \lipsum[1-1][4-6]

\end{document}

Output:

• BTW, \comment is also used by other packages (defined differently). – John Kormylo May 13 '19 at 3:58

Quite likely you want all of your margin notes to be single spaced.

\documentclass{article}
\usepackage{changes,etoolbox}

\usepackage{lipsum}

\makeatletter
\makeatother

\begin{document}

\lipsum[1-1][1-3]\comment{I would like this comment to be single-spaced.}
\lipsum[1-1][4-6]

\end{document}

Explanation: \@marginparreset is the hook that the LaTeX kernel provides for doing initializations before starting to typeset a margin paragraph (internally used by the changes package).

\documentclass{article}
\usepackage{changes}
\usepackage{lipsum}

\begin{document}
\lipsum[1-1][1-3]\renewcommand*{\baselinestretch}{1}\comment{\selectfont
I would like this comment to be single-spaced.}
\lipsum[1-1][4-6]

\end{document}

which seems to work. If you decide this is the way to go, then obviously one may make it more automatic and safer by patching this into \comment. You could just look up its definition from changes.sty and redefine it as follows:

\documentclass{article}
\usepackage{changes}
\usepackage{lipsum}
\makeatletter
\renewcommand*{\comment}[2][\@empty]{%
\edef\oldbaselinestretch{\baselinestretch}%
\typeout{\oldbaselinestretch}%
\renewcommand*{\baselinestretch}{1}%
\setkeys{Changes@comment}{#1}%
\Changes@output%
{comment}%
{\Changes@comment@id}%
{}%
{}%
{\selectfont #2}%
{\changescommentname}%
{\selectfont #2}%
\renewcommand*{\baselinestretch}{\oldbaselinestretch}%
}
\makeatother
\begin{document}
\lipsum[1-1][1-3]\comment{I would like this comment to be single-spaced.}
\lipsum[1-1][4-6]

\selectfont
\lipsum[1-1]

\end{document}

• Clever! I was trying to fix \baselineskip, which has to be done before the paragraph starts. I found only one \marginpar in the changes source, but patching it didn't do anything. – John Kormylo May 13 '19 at 4:00
• @JohnKormylo Thanks! All I did was to look up Ulrike's answer and use the information there. – user121799 May 13 '19 at 4:01


text:
# choosing best n points on sine wave for wave generation

I want to generate a sine wave using DAC+DMA. Currently, I have an example that generates a sine wave using DAC+DMA from an array of 60 points, at 8KHz. I want to be able to increase the frequency up to 12KHz, in increments of 100Hz. To do this without losing precision, I might need to lower the number of points per wave as the frequency increases. I wanted to ask the following:

1. Can you recommend a function (preferable in C, but pseudo code is also good, I just don't know the technical terms to search for it) to calculate the following function:

void get_best_n_points_for_sine_wave_plot(int n, uint32* array);

Which gets an input value n, and writes into array the n numbers that give the best n points to plot the wave on DAC (I suppose the lowest and highest points must be there, and the rest are scattered evenly before, between and after them? this is just a guess and I prefer your educated input)

1. any better way you could suggest to do this?

Thanks!

• As long as you meet the nyquist criteria (to the level that only you can decide) you can choose wherever you want those points to be with impunity. – Andy aka Feb 20 at 10:31
• How fast is your DAC? – user253751 Feb 20 at 10:36
• sure its an unsigned integer pointer ? – Sorenp Feb 20 at 10:48
• I will check the DAC speed a bit later, can you pleas etel me why it's important? – Ilans Feb 20 at 10:55
• yes, the sine wave starts at 0. but even if the output array goes +-, it's just adding a constant value to the entire array to get it to what I want, so it doesn't matter – Ilans Feb 20 at 10:56

I'm interpreting this as your sample rate is 60*8=480kHz.

You'll be hard pressed to find a convenient sample set that gives you linear accuracy, since changing the frequency of a sampled signal is geometric. Depending on your accuracy requirements, your table could become enormous.

Depending on your processor speed, you could probably implement a 2-pole IIR. Put the poles right on the unit circle in the Z plane, at the angles representing the frequency of interest, and keep the coefficients for each frequency. In your IIR, you can then simply switch in the coefficients for that frequency as required.

This requires a set of coefficients for each frequency, rather than what would almost be a sine table for each frequency. It's computationally far less taxing than calculating sin(x) for each sample. If you wanted to go fully continuous, you could calculate the coefficients each time the frequency is changed. The per-sample IIR calculations can be batched to your DMA size for efficiency.

If this isn't an option, or if you have arbitrarily large amounts of memory, you might want to include tolerances for your output frequency that would help us suggest table optimizations.

• Thanks for your answer, but it will require me to learn and test new things, something which sadly I currently have no time to do. Memory is not an issue. I prefer the easiest and fastest solution. I just want a function / pseudo-code to do what I defined or something equally simple. – Ilans Feb 20 at 15:27
• Then what are your tolerances on the frequencies? If you want them exact, you'll essentially need 21 independent tables. Even though they might have points in common, the indexing wouldn't be worth it. – Cristobol Polychronopolis Feb 20 at 16:07

See if you can break the rules for the sample rate. I expect you can arbitrarily change the sample rate to scale your output frequency, same table, same data points.

I interpret your requirement is to generate all frequencies on 100Hz steps from 8kHz to 12kHz.

The simplest way to do this is with a single sine table, and a sampling rate that would generate 100Hz if you single stepped through it. For 200Hz, you would skip through 2 at a time, for 8kHz you'd skip through 80 at a time. This will as a byproduct give you all multiples of 100Hz, up to the Nyquist rate.

One possible choice would be a 480 entry table, and a sample rate of 48kHz, which is a nice audio standard, and also a simple division from your 144MHz clock. Your top frequency is only 25% of the sample rate, so the anti-alias filter design is relatively straightforward. For least consumption of resources, your DMA must be able to wrap numbers modulo 480, or your CPU be fast enough to do that. The relatively low sample rate means there are plenty of CPU cycles to do the trivial operations needed. See the last paragraph for how to use a single stepping DMA.

Another choice would be a 512 long table, with a 51.2kHz sample rate, with a saving in the modulo arithmetic, at the expense of a trickier sample rate.

Pseudocode to generate the table

TABLE_LEN = 480   # or 512, or whatever
for index in (0 to TABLE_LEN-1):
datum = sin(2*pi*index/TABLE_LEN)

Pseudocode to step through the table with the CPU, with a binary table length, assuming you get an interrupt every tick of the sample rate

int RESOLUTION = 100
int tab_pointer = 0
int incr = freq/RESOLUTION

interrupt_function:
tab_pointer += incr
tab_pointer &= TABLE_LEN-1     # mask so there's no carry out to higher bits
dac = sine_table[tab_pointer]

Pseudocode to step through the table with the CPU, with an arbitrary table length, binary or not, assuming you get an interrupt every tick of the sample rate

int RESOLUTION = 100
int tab_pointer = 0
int incr = freq/RESOLUTION

interrupt_function:
tab_pointer += incr
if tab_pointer >= TABLE_LEN:
tab_pointer -= TABLE_LEN

dac = sine_table[tab_pointer]

If you still want to DMA to the DAC, and the DMA will only handle increments of a single address, then there's still a fairly quick way to do it. Build a table 480 long with the samples in the correct order, by using the second 'generation' function, but outputting to your new table rather than the DAC. If you need the speed between frequency changes, then read from your first 100Hz table. If you don't need the speed and want to economise on memory, then lose the intermediate 100Hz table, and build it directly from the sin function.