text:
<?php
    class AvailabilityManager extends Manager
    {
        public function get($idClassroom = -1, $idAvailability = -1)
        {
            $requestSQL = 'SELECT Id_availability,
                                  Id_classroom,
                                  Date,
                                  StartTime,
                                  EndTime FROM Availabilities';

            $paramsSQL = array();

            if($idClassroom != -1)
            {
                $requestSQL .= ' WHERE Id_classroom = ?';
                $paramsSQL[] = $idClassroom;
            }

            if($idAvailability != -1)
            {
                $connect = ($idClassroom != -1) ? 'AND' : 'WHERE';
                $requestSQL .= ' ' . $connect .' Id_availability = ?';
                $paramsSQL[] = $idAvailability;
            }

            $req = $this->m_dao->prepare($requestSQL);
            $req->execute($paramsSQL);

            $availabilities = array();

            while($data = $req->fetch())
            {
                $date = new Date;
                $date->setFromMySQLResult($data['Date']);

                $startTime = new Time;
                $startTime->setFromString($data['StartTime']);

                $endTime = new Time;
                $endTime->setFromString($data['EndTime']);

                $availability = new Availability;
                $availability->setId($data['Id_availability']);
                $availability->setIdClassroom($data['Id_classroom']);
                $availability->setDate($date);
                $availability->setStartTime($startTime);
                $availability->setEndTime($endTime);

                $availabilities[] = $availability;
            }

            return $availabilities;
        }

        public function save($availabilities)
        {
            $req = $this->m_dao->prepare('INSERT INTO Availabilities(Id_classroom,
                                                                     Date,
                                                                     StartTime,
                                                                     EndTime) VALUES(?, ?, ?, ?)');

            foreach($availabilities as $availability)
            {
                $req->execute(array($availability->getIdClassroom(),
                                    $availability->getDate()->toStringMySQL(),
                                    $availability->getStartTime()->toStringMySQL(),
                                    $availability->getEndTime()->toStringMySQL()));
            }
        }

       public function update($availability)
        {
            $req = $this->m_dao->prepare('UPDATE Availabilities SET Date = ?,
                                                                    StartTime = ?,
                                                                    EndTime = ? WHERE Id_availability = ?');

            $req->execute(array($availability->getDate()->toStringMySQL(),
                                $availability->getStartTime()->toStringMySQL(),
                                $availability->getEndTime()->toStringMySQL(),
                                $availability->getId()));
        }

        public function delete($availabilityIds)
        {
            $req = $this->m_dao->prepare('DELETE FROM Availabilities WHERE Id_availability = ?');

            foreach($availabilityIds as $availabilityId)
                $req->execute(array($availabilityId));
        }
    }
?>


text:
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6
// See http://java.sun.com/xml/jaxb
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2012.04.20 at 03:09:04 PM EDT
//

package org.slc.sli.sample.entities;

import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlEnumValue;
import javax.xml.bind.annotation.XmlType;

/**
 *
Java class for IncidentBehaviorType.
 *
 *
The following schema fragment specifies the expected content contained within this class.
 *

 *

 * <simpleType name="IncidentBehaviorType">
 *   <restriction base="{http://www.w3.org/2001/XMLSchema}token">
 *     <enumeration value="Alcohol"/>
 *     <enumeration value="Arson"/>
 *     <enumeration value="Attendance Policy Violation"/>
 *     <enumeration value="Battery"/>
 *     <enumeration value="Burglary/Breaking and Entering"/>
 *     <enumeration value="Disorderly Conduct"/>
 *     <enumeration value="Drugs Excluding Alcohol and Tobacco"/>
 *     <enumeration value="Fighting"/>
 *     <enumeration value="Harassment, Nonsexual"/>
 *     <enumeration value="Harassment, Sexual"/>
 *     <enumeration value="Homicide"/>
 *     <enumeration value="Inappropriate Use of Medication"/>
 *     <enumeration value="Insubordination"/>
 *     <enumeration value="Kidnapping"/>
 *     <enumeration value="Obscene Behavior"/>
 *     <enumeration value="Physical Altercation, Minor"/>
 *     <enumeration value="Robbery"/>
 *     <enumeration value="School Threat"/>
 *     <enumeration value="Theft"/>
 *     <enumeration value="Threat/Intimidation"/>
 *     <enumeration value="Tobacco Possession or Use"/>
 *     <enumeration value="Trespassing"/>
 *     <enumeration value="Vandalism"/>
 *     <enumeration value="Violation of School Rules"/>
 *     <enumeration value="Weapons Possession"/>
 *     <enumeration value="Harassment or bullying on the basis of disability"/>
 *     <enumeration value="Harassment or bullying on the basis of race, color, or national origin"/>
 *     <enumeration value="Harassment or bullying on the basis of sex"/>
 *   </restriction>
 * </simpleType>
 *

 *
 */
@XmlType(name = "IncidentBehaviorType")
@XmlEnum
public enum IncidentBehaviorType {

    @XmlEnumValue("Alcohol")
    ALCOHOL("Alcohol"),
    @XmlEnumValue("Arson")
    ARSON("Arson"),
    @XmlEnumValue("Attendance Policy Violation")
    ATTENDANCE_POLICY_VIOLATION("Attendance Policy Violation"),
    @XmlEnumValue("Battery")
    BATTERY("Battery"),
    @XmlEnumValue("Burglary/Breaking and Entering")
    BURGLARY_BREAKING_AND_ENTERING("Burglary/Breaking and Entering"),
    @XmlEnumValue("Disorderly Conduct")
    DISORDERLY_CONDUCT("Disorderly Conduct"),
    @XmlEnumValue("Drugs Excluding Alcohol and Tobacco")
    DRUGS_EXCLUDING_ALCOHOL_AND_TOBACCO("Drugs Excluding Alcohol and Tobacco"),
    @XmlEnumValue("Fighting")
    FIGHTING("Fighting"),
    @XmlEnumValue("Harassment, Nonsexual")
    HARASSMENT_NONSEXUAL("Harassment, Nonsexual"),
    @XmlEnumValue("Harassment, Sexual")
    HARASSMENT_SEXUAL("Harassment, Sexual"),
    @XmlEnumValue("Homicide")
    HOMICIDE("Homicide"),
    @XmlEnumValue("Inappropriate Use of Medication")
    INAPPROPRIATE_USE_OF_MEDICATION("Inappropriate Use of Medication"),
    @XmlEnumValue("Insubordination")
    INSUBORDINATION("Insubordination"),
    @XmlEnumValue("Kidnapping")
    KIDNAPPING("Kidnapping"),
    @XmlEnumValue("Obscene Behavior")
    OBSCENE_BEHAVIOR("Obscene Behavior"),
    @XmlEnumValue("Physical Altercation, Minor")
    PHYSICAL_ALTERCATION_MINOR("Physical Altercation, Minor"),
    @XmlEnumValue("Robbery")
    ROBBERY("Robbery"),
    @XmlEnumValue("School Threat")
    SCHOOL_THREAT("School Threat"),
    @XmlEnumValue("Theft")
    THEFT("Theft"),
    @XmlEnumValue("Threat/Intimidation")
    THREAT_INTIMIDATION("Threat/Intimidation"),
    @XmlEnumValue("Tobacco Possession or Use")
    TOBACCO_POSSESSION_OR_USE("Tobacco Possession or Use"),
    @XmlEnumValue("Trespassing")
    TRESPASSING("Trespassing"),
    @XmlEnumValue("Vandalism")
    VANDALISM("Vandalism"),
    @XmlEnumValue("Violation of School Rules")
    VIOLATION_OF_SCHOOL_RULES("Violation of School Rules"),
    @XmlEnumValue("Weapons Possession")
    WEAPONS_POSSESSION("Weapons Possession"),
    @XmlEnumValue("Harassment or bullying on the basis of disability")
    HARASSMENT_OR_BULLYING_ON_THE_BASIS_OF_DISABILITY("Harassment or bullying on the basis of disability"),
    @XmlEnumValue("Harassment or bullying on the basis of race, color, or national origin")
    HARASSMENT_OR_BULLYING_ON_THE_BASIS_OF_RACE_COLOR_OR_NATIONAL_ORIGIN("Harassment or bullying on the basis of race, color, or national origin"),
    @XmlEnumValue("Harassment or bullying on the basis of sex")
    HARASSMENT_OR_BULLYING_ON_THE_BASIS_OF_SEX("Harassment or bullying on the basis of sex");
    private final String value;

    IncidentBehaviorType(String v) {
        value = v;
    }

    public String value() {
        return value;
    }

    public static IncidentBehaviorType fromValue(String v) {
        for (IncidentBehaviorType c: IncidentBehaviorType.values()) {
            if (c.value.equals(v)) {
                return c;
            }
        }
        throw new IllegalArgumentException(v);
    }

}

redpajama_set_name: RedPajamaGithub


text:
module Text.RSS.Export where

import Text.XML.Light as XML
import Text.RSS.Syntax

import Data.Maybe

qualNode :: String -> [XML.Content] -> XML.Element
qualNode n cs =
  blank_element
    { elName    = qualName n
    , elContent = cs
    }

qualName :: String -> QName
qualName n = QName{qName=n,qURI=Nothing,qPrefix=Nothing}

---
xmlRSS :: RSS -> XML.Element
xmlRSS r =
  (qualNode "rss" $ map Elem $
    (  [ xmlChannel (rssChannel r) ]
    ++ rssOther r))
    { elAttribs = (Attr (qualName "version") (rssVersion r)):rssAttrs r }

xmlChannel :: RSSChannel -> XML.Element
xmlChannel ch =
   (qualNode "channel" $ map Elem $
     ( [ xmlLeaf "title" (rssTitle ch)
       , xmlLeaf "link"  (rssLink ch)
       , xmlLeaf "description" (rssDescription ch)
       ]
      ++ map xmlItem (rssItems ch)
      ++ mb (xmlLeaf "language")  (rssLanguage ch)
      ++ mb (xmlLeaf "copyright") (rssCopyright ch)
      ++ mb (xmlLeaf "managingEditor") (rssEditor ch)
      ++ mb (xmlLeaf "webMaster") (rssWebMaster ch)
      ++ mb (xmlLeaf "pubDate")   (rssPubDate ch)
      ++ mb (xmlLeaf "lastBuildDate") (rssLastUpdate ch)
      ++ map xmlCategory (rssCategories ch)
      ++ mb (xmlLeaf "generator") (rssGenerator ch)
      ++ mb (xmlLeaf "docs") (rssDocs ch)
      ++ mb xmlCloud (rssCloud ch)
      ++ mb ((xmlLeaf "ttl") . show) (rssTTL ch)
      ++ mb xmlImage (rssImage ch)
      ++ mb (xmlLeaf "rating") (rssRating ch)
      ++ mb xmlTextInput (rssTextInput ch)
      ++ mb xmlSkipHours (rssSkipHours ch)
      ++ mb xmlSkipDays  (rssSkipDays ch)
      ++ rssChannelOther ch))

xmlItem :: RSSItem -> XML.Element
xmlItem it =
   (qualNode "item" $ map Elem $
     (  mb  (xmlLeaf "title") (rssItemTitle it)
     ++ mb  (xmlLeaf "link")  (rssItemLink it)
     ++ mb  (xmlLeaf "description") (rssItemDescription it)
     ++ mb  (xmlLeaf "author") (rssItemAuthor it)
     ++ map xmlCategory (rssItemCategories it)
     ++ mb  (xmlLeaf "comments") (rssItemComments it)
     ++ mb  xmlEnclosure (rssItemEnclosure it)
     ++ mb  xmlGuid (rssItemGuid it)
     ++ mb  (xmlLeaf "pubDate") (rssItemPubDate it)
     ++ mb  xmlSource (rssItemSource it)
     ++ rssItemOther it))
      { elAttribs = rssItemAttrs it }

xmlSource :: RSSSource -> XML.Element
xmlSource s =
   (xmlLeaf "source" (rssSourceTitle s))
     { elAttribs = (Attr (qualName "url") (rssSourceURL s)) :
                   rssSourceAttrs s }

xmlEnclosure :: RSSEnclosure -> XML.Element
xmlEnclosure e =
   (xmlLeaf "enclosure" "")
     { elAttribs =
        (Attr (qualName "url")    (rssEnclosureURL e)) :
        (Attr (qualName "length") (show $ rssEnclosureLength e)) :
        (Attr (qualName "type")   (rssEnclosureType e)) :
        rssEnclosureAttrs e }

xmlCategory :: RSSCategory -> XML.Element
xmlCategory c =
   (xmlLeaf "category" (rssCategoryValue c))
     { elAttribs =
        (fromMaybe id (fmap (\ n -> ((Attr (qualName "domain") n):))
                            (rssCategoryDomain c))) $
             (rssCategoryAttrs c) }

xmlGuid :: RSSGuid -> XML.Element
xmlGuid g =
   (xmlLeaf "guid" (rssGuidValue g))
     { elAttribs =
        (fromMaybe id (fmap (\ n -> ((Attr (qualName "isPermaLink") (toBool n)):))
                            (rssGuidPermanentURL g))) $
             (rssGuidAttrs g) }
 where
  toBool False = "false"
  toBool _ = "true"

xmlImage :: RSSImage -> XML.Element
xmlImage im =
   (qualNode "image" $ map Elem $
     ( [ xmlLeaf "url"   (rssImageURL im)
       , xmlLeaf "title" (rssImageTitle im)
       , xmlLeaf "link"  (rssImageLink im)
       ]
       ++ mb ((xmlLeaf "width")  . show) (rssImageWidth im)
       ++ mb ((xmlLeaf "height") . show) (rssImageHeight im)
       ++ mb (xmlLeaf "description") (rssImageDesc im)
       ++ rssImageOther im))

xmlCloud :: RSSCloud -> XML.Element
xmlCloud cl =
    (xmlLeaf "cloud" "")
     { elAttribs =
         (  mb (Attr (qualName "domain")) (rssCloudDomain cl)
         ++ mb (Attr (qualName "port"))   (rssCloudPort cl)
         ++ mb (Attr (qualName "path"))   (rssCloudPath cl)
         ++ mb (Attr (qualName "registerProcedure")) (rssCloudRegisterProcedure cl)
         ++ mb (Attr (qualName "protocol")) (rssCloudProtocol cl)
         ++ rssCloudAttrs cl) }

xmlTextInput :: RSSTextInput -> XML.Element
xmlTextInput ti =
   (qualNode "textInput" $ map Elem $
     ( [ xmlLeaf "title" (rssTextInputTitle ti)
       , xmlLeaf "description"   (rssTextInputDesc ti)
       , xmlLeaf "name"  (rssTextInputName ti)
       , xmlLeaf "link"  (rssTextInputLink ti)
       ] ++ rssTextInputOther ti))
     { elAttribs = rssTextInputAttrs ti }

xmlSkipHours :: [Integer] -> XML.Element
xmlSkipHours hs =
  (qualNode "skipHours" $ map Elem $
    (map (\ n -> xmlLeaf "hour" (show n)) hs))

xmlSkipDays :: [String] -> XML.Element
xmlSkipDays hs =
  (qualNode "skipDays" $ map Elem $
    (map (\ n -> xmlLeaf "day" n) hs))

--

xmlAttr :: String -> String -> XML.Attr
xmlAttr k v = Attr (qualName k) v

xmlLeaf :: String -> String -> XML.Element
xmlLeaf tg txt =
 blank_element{ elName = qualName tg
               , elContent = [ Text blank_cdata { cdData = txt } ]
              }

---
mb :: (a -> b) -> Maybe a -> [b]
mb _ Nothing = []
mb f (Just x) = [f x]


text:
function Add-DebugNote
{
    param($Id, $Message)
    if ($script:DebugAST)
    {
        $debugID = New-Guid
        node -Name $debugID @{label = $Message; shape = 'plaintext'}
        edge -From $debugID -To $Id @{style = 'dotted'; arrowhead = 'none'}
    }
}


text:
package com.siyeh.ig.performance;

import com.intellij.codeInspection.CommonQuickFixBundle;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiUtil;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.InspectionGadgetsFix;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class MapReplaceableByEnumMapInspection extends BaseInspection {

  @Override
  @NotNull
  public String getDisplayName() {
    return InspectionGadgetsBundle.message("map.replaceable.by.enum.map.display.name");
  }

  @Override
  @NotNull
  protected String buildErrorString(Object... infos) {
    return InspectionGadgetsBundle.message("map.replaceable.by.enum.map.problem.descriptor");
  }

  @Override
  public BaseInspectionVisitor buildVisitor() {
    return new MapReplaceableByEnumMapVisitor();
  }

  @Nullable
  @Override
  protected InspectionGadgetsFix buildFix(Object... infos) {
    if (infos.length != 1) return null;
    PsiLocalVariable localVariable = (PsiLocalVariable)infos[0];
    PsiType[] parameters = CollectionReplaceableByEnumCollectionVisitor.extractParameterType(localVariable, 2);
    if (parameters == null) return null;
    PsiType enumParameter = parameters[0];
    String parameterListText = Arrays.stream(parameters).map(PsiType::getCanonicalText).collect(Collectors.joining(",", "<", ">"));
    PsiClass probablyEnum = PsiUtil.resolveClassInClassTypeOnly(enumParameter);
    if (probablyEnum == null || !probablyEnum.isEnum()) return null;
    String text = "new java.util.EnumMap" + parameterListText + "(" + enumParameter.getCanonicalText() + ".class)";
    return new ReplaceExpressionWithTextFix(text, CommonQuickFixBundle.message("fix.replace.with.x", "EnumMap"));
  }

  private static class MapReplaceableByEnumMapVisitor extends CollectionReplaceableByEnumCollectionVisitor {

    @Override
    @NotNull
    protected List<String> getUnreplaceableCollectionNames() {
      return Arrays.asList(CommonClassNames.JAVA_UTIL_CONCURRENT_HASH_MAP, "java.util.concurrent.ConcurrentSkipListMap",
                           "java.util.LinkedHashMap");
    }

    @NotNull
    @Override
    protected List<String> getReplaceableCollectionNames() {
      return Collections.singletonList(CommonClassNames.JAVA_UTIL_HASH_MAP);
    }

    @Override
    @NotNull
    protected String getReplacementCollectionName() {
      return "java.util.EnumMap";
    }

    @Override
    @NotNull
    protected String getBaseCollectionName() {
      return CommonClassNames.JAVA_UTIL_MAP;
    }

  }
}


text:
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information
namespace Dnn.PersonaBar.Vocabularies.Services.Dto
{
    using System;
    using System.Data;
    using System.Runtime.Serialization;

    using DotNetNuke.ComponentModel.DataAnnotations;
    using Newtonsoft.Json;

    [JsonObject]
    public class VocabularyDto
    {
        [JsonProperty("name")]
        public string Name { get; set; }

        [JsonProperty("description")]
        public string Description { get; set; }

        [JsonProperty("scopeType")]
        public string ScopeType { get; set; }

        [JsonProperty("scopeTypeId")]
        public int ScopeTypeId { get; set; }

        [JsonProperty("type")]
        public string Type { get; set; }

        [JsonProperty("typeId")]
        public int TypeId { get; set; }

        [JsonProperty("vocabularyId")]
        public int VocabularyId { get; set; }
    }
}


text:
import path from "path";

class LessError extends Error {
  constructor(error) {
    super();

    this.message = [
      "\n",
      ...LessError.getFileExcerptIfPossible(error),
      error.message.charAt(0).toUpperCase() + error.message.slice(1),
      error.filename
        ? `      Error in ${path.normalize(error.filename)} (line ${
            error.line
          }, column ${error.column})`
        : "",
    ].join("\n");

    this.hideStack = true;
  }

  static getFileExcerptIfPossible(lessError) {
    if (typeof lessError.extract === "undefined") {
      return [];
    }

    const excerpt = lessError.extract.slice(0, 2);
    const column = Math.max(lessError.column - 1, 0);

    if (typeof excerpt[0] === "undefined") {
      excerpt.shift();
    }

    excerpt.push(`${new Array(column).join(" ")}^`);

    return excerpt;
  }
}

export default LessError;


text:
import React from 'react';
import { render } from 'react-dom';
import { AppContainer } from 'react-hot-loader';
import Root from './containers/Root';

render(
  <AppContainer>
    <Root />
  </AppContainer>,
  document.getElementById('root')
);

if (module.hot) {
  module.hot.accept('./containers/Root', () => {
    // eslint-disable-next-line global-require
    const NextRoot = require('./containers/Root').default;
    render(
      <AppContainer>
        <NextRoot />
      </AppContainer>,
      document.getElementById('root')
    );
  });
}


text:
namespace Dropbox.Api.Sharing
{
    using sys = System;
    using col = System.Collections.Generic;
    using re = System.Text.RegularExpressions;

    using enc = Dropbox.Api.Stone;

    /// <summary>
    /// <para>The remove folder member error object</para>
    /// </summary>
    public class RemoveFolderMemberError
    {
        #pragma warning disable 108

        /// <summary>
        /// <para>The encoder instance.</para>
        /// </summary>
        internal static enc.StructEncoder<RemoveFolderMemberError> Encoder = new RemoveFolderMemberErrorEncoder();

        /// <summary>
        /// <para>The decoder instance.</para>
        /// </summary>
        internal static enc.StructDecoder<RemoveFolderMemberError> Decoder = new RemoveFolderMemberErrorDecoder();

        /// <summary>
        /// <para>Initializes a new instance of the <see cref="RemoveFolderMemberError" />
        /// class.</para>
        /// </summary>
        public RemoveFolderMemberError()
        {
        }

        /// <summary>
        /// <para>Gets a value indicating whether this instance is AccessError</para>
        /// </summary>
        public bool IsAccessError
        {
            get
            {
                return this is AccessError;
            }
        }

        /// <summary>
        /// <para>Gets this instance as a AccessError, or <c>null</c>.</para>
        /// </summary>
        public AccessError AsAccessError
        {
            get
            {
                return this as AccessError;
            }
        }

        /// <summary>
        /// <para>Gets a value indicating whether this instance is MemberError</para>
        /// </summary>
        public bool IsMemberError
        {
            get
            {
                return this is MemberError;
            }
        }

        /// <summary>
        /// <para>Gets this instance as a MemberError, or <c>null</c>.</para>
        /// </summary>
        public MemberError AsMemberError
        {
            get
            {
                return this as MemberError;
            }
        }

        /// <summary>
        /// <para>Gets a value indicating whether this instance is FolderOwner</para>
        /// </summary>
        public bool IsFolderOwner
        {
            get
            {
                return this is FolderOwner;
            }
        }

        /// <summary>
        /// <para>Gets this instance as a FolderOwner, or <c>null</c>.</para>
        /// </summary>
        public FolderOwner AsFolderOwner
        {
            get
            {
                return this as FolderOwner;
            }
        }

        /// <summary>
        /// <para>Gets a value indicating whether this instance is GroupAccess</para>
        /// </summary>
        public bool IsGroupAccess
        {
            get
            {
                return this is GroupAccess;
            }
        }

        /// <summary>
        /// <para>Gets this instance as a GroupAccess, or <c>null</c>.</para>
        /// </summary>
        public GroupAccess AsGroupAccess
        {
            get
            {
                return this as GroupAccess;
            }
        }

        /// <summary>
        /// <para>Gets a value indicating whether this instance is TeamFolder</para>
        /// </summary>
        public bool IsTeamFolder
        {
            get
            {
                return this is TeamFolder;
            }
        }

        /// <summary>
        /// <para>Gets this instance as a TeamFolder, or <c>null</c>.</para>
        /// </summary>
        public TeamFolder AsTeamFolder
        {
            get
            {
                return this as TeamFolder;
            }
        }

        /// <summary>
        /// <para>Gets a value indicating whether this instance is NoPermission</para>
        /// </summary>
        public bool IsNoPermission
        {
            get
            {
                return this is NoPermission;
            }
        }

        /// <summary>
        /// <para>Gets this instance as a NoPermission, or <c>null</c>.</para>
        /// </summary>
        public NoPermission AsNoPermission
        {
            get
            {
                return this as NoPermission;
            }
        }

        /// <summary>
        /// <para>Gets a value indicating whether this instance is TooManyFiles</para>
        /// </summary>
        public bool IsTooManyFiles
        {
            get
            {
                return this is TooManyFiles;
            }
        }

        /// <summary>
        /// <para>Gets this instance as a TooManyFiles, or <c>null</c>.</para>
        /// </summary>
        public TooManyFiles AsTooManyFiles
        {
            get
            {
                return this as TooManyFiles;
            }
        }

        /// <summary>
        /// <para>Gets a value indicating whether this instance is Other</para>
        /// </summary>
        public bool IsOther
        {
            get
            {
                return this is Other;
            }
        }

        /// <summary>
        /// <para>Gets this instance as a Other, or <c>null</c>.</para>
        /// </summary>
        public Other AsOther
        {
            get
            {
                return this as Other;
            }
        }

        #region Encoder class

        /// <summary>
        /// <para>Encoder for  <see cref="RemoveFolderMemberError" />.</para>
        /// </summary>
        private class RemoveFolderMemberErrorEncoder : enc.StructEncoder<RemoveFolderMemberError>
        {
            /// <summary>
            /// <para>Encode fields of given value.</para>
            /// </summary>
            /// <param name="value">The value.</param>
            /// <param name="writer">The writer.</param>
            public override void EncodeFields(RemoveFolderMemberError value, enc.IJsonWriter writer)
            {
                if (value is AccessError)
                {
                    WriteProperty(".tag", "access_error", writer, enc.StringEncoder.Instance);
                    AccessError.Encoder.EncodeFields((AccessError)value, writer);
                    return;
                }
                if (value is MemberError)
                {
                    WriteProperty(".tag", "member_error", writer, enc.StringEncoder.Instance);
                    MemberError.Encoder.EncodeFields((MemberError)value, writer);
                    return;
                }
                if (value is FolderOwner)
                {
                    WriteProperty(".tag", "folder_owner", writer, enc.StringEncoder.Instance);
                    FolderOwner.Encoder.EncodeFields((FolderOwner)value, writer);
                    return;
                }
                if (value is GroupAccess)
                {
                    WriteProperty(".tag", "group_access", writer, enc.StringEncoder.Instance);
                    GroupAccess.Encoder.EncodeFields((GroupAccess)value, writer);
                    return;
                }
                if (value is TeamFolder)
                {
                    WriteProperty(".tag", "team_folder", writer, enc.StringEncoder.Instance);
                    TeamFolder.Encoder.EncodeFields((TeamFolder)value, writer);
                    return;
                }
                if (value is NoPermission)
                {
                    WriteProperty(".tag", "no_permission", writer, enc.StringEncoder.Instance);
                    NoPermission.Encoder.EncodeFields((NoPermission)value, writer);
                    return;
                }
                if (value is TooManyFiles)
                {
                    WriteProperty(".tag", "too_many_files", writer, enc.StringEncoder.Instance);
                    TooManyFiles.Encoder.EncodeFields((TooManyFiles)value, writer);
                    return;
                }
                if (value is Other)
                {
                    WriteProperty(".tag", "other", writer, enc.StringEncoder.Instance);
                    Other.Encoder.EncodeFields((Other)value, writer);
                    return;
                }
                throw new sys.InvalidOperationException();
            }
        }

        #endregion

        #region Decoder class

        /// <summary>
        /// <para>Decoder for  <see cref="RemoveFolderMemberError" />.</para>
        /// </summary>
        private class RemoveFolderMemberErrorDecoder : enc.UnionDecoder<RemoveFolderMemberError>
        {
            /// <summary>
            /// <para>Create a new instance of type <see cref="RemoveFolderMemberError"
            /// />.</para>
            /// </summary>
            /// <returns>The struct instance.</returns>
            protected override RemoveFolderMemberError Create()
            {
                return new RemoveFolderMemberError();
            }

            /// <summary>
            /// <para>Decode based on given tag.</para>
            /// </summary>
            /// <param name="tag">The tag.</param>
            /// <param name="reader">The json reader.</param>
            /// <returns>The decoded object.</returns>
            protected override RemoveFolderMemberError Decode(string tag, enc.IJsonReader reader)
            {
                switch (tag)
                {
                    case "access_error":
                        return AccessError.Decoder.DecodeFields(reader);
                    case "member_error":
                        return MemberError.Decoder.DecodeFields(reader);
                    case "folder_owner":
                        return FolderOwner.Decoder.DecodeFields(reader);
                    case "group_access":
                        return GroupAccess.Decoder.DecodeFields(reader);
                    case "team_folder":
                        return TeamFolder.Decoder.DecodeFields(reader);
                    case "no_permission":
                        return NoPermission.Decoder.DecodeFields(reader);
                    case "too_many_files":
                        return TooManyFiles.Decoder.DecodeFields(reader);
                    default:
                        return Other.Decoder.DecodeFields(reader);
                }
            }
        }

        #endregion

        /// <summary>
        /// <para>The access error object</para>
        /// </summary>
        public sealed class AccessError : RemoveFolderMemberError
        {
            #pragma warning disable 108

            /// <summary>
            /// <para>The encoder instance.</para>
            /// </summary>
            internal static enc.StructEncoder<AccessError> Encoder = new AccessErrorEncoder();

            /// <summary>
            /// <para>The decoder instance.</para>
            /// </summary>
            internal static enc.StructDecoder<AccessError> Decoder = new AccessErrorDecoder();

            /// <summary>
            /// <para>Initializes a new instance of the <see cref="AccessError" />
            /// class.</para>
            /// </summary>
            /// <param name="value">The value</param>
            public AccessError(SharedFolderAccessError value)
            {
                this.Value = value;
            }
            /// <summary>
            /// <para>Initializes a new instance of the <see cref="AccessError" />
            /// class.</para>
            /// </summary>
            private AccessError()
            {
            }

            /// <summary>
            /// <para>Gets the value of this instance.</para>
            /// </summary>
            public SharedFolderAccessError Value { get; private set; }

            #region Encoder class

            /// <summary>
            /// <para>Encoder for  <see cref="AccessError" />.</para>
            /// </summary>
            private class AccessErrorEncoder : enc.StructEncoder<AccessError>
            {
                /// <summary>
                /// <para>Encode fields of given value.</para>
                /// </summary>
                /// <param name="value">The value.</param>
                /// <param name="writer">The writer.</param>
                public override void EncodeFields(AccessError value, enc.IJsonWriter writer)
                {
                    WriteProperty("access_error", value.Value, writer, global::Dropbox.Api.Sharing.SharedFolderAccessError.Encoder);
                }
            }

            #endregion

            #region Decoder class

            /// <summary>
            /// <para>Decoder for  <see cref="AccessError" />.</para>
            /// </summary>
            private class AccessErrorDecoder : enc.StructDecoder<AccessError>
            {
                /// <summary>
                /// <para>Create a new instance of type <see cref="AccessError" />.</para>
                /// </summary>
                /// <returns>The struct instance.</returns>
                protected override AccessError Create()
                {
                    return new AccessError();
                }

                /// <summary>
                /// <para>Set given field.</para>
                /// </summary>
                /// <param name="value">The field value.</param>
                /// <param name="fieldName">The field name.</param>
                /// <param name="reader">The json reader.</param>
                protected override void SetField(AccessError value, string fieldName, enc.IJsonReader reader)
                {
                    switch (fieldName)
                    {
                        case "access_error":
                            value.Value = global::Dropbox.Api.Sharing.SharedFolderAccessError.Decoder.Decode(reader);
                            break;
                        default:
                            reader.Skip();
                            break;
                    }
                }
            }

            #endregion
        }

        /// <summary>
        /// <para>The member error object</para>
        /// </summary>
        public sealed class MemberError : RemoveFolderMemberError
        {
            #pragma warning disable 108

            /// <summary>
            /// <para>The encoder instance.</para>
            /// </summary>
            internal static enc.StructEncoder<MemberError> Encoder = new MemberErrorEncoder();

            /// <summary>
            /// <para>The decoder instance.</para>
            /// </summary>
            internal static enc.StructDecoder<MemberError> Decoder = new MemberErrorDecoder();

            /// <summary>
            /// <para>Initializes a new instance of the <see cref="MemberError" />
            /// class.</para>
            /// </summary>
            /// <param name="value">The value</param>
            public MemberError(SharedFolderMemberError value)
            {
                this.Value = value;
            }
            /// <summary>
            /// <para>Initializes a new instance of the <see cref="MemberError" />
            /// class.</para>
            /// </summary>
            private MemberError()
            {
            }

            /// <summary>
            /// <para>Gets the value of this instance.</para>
            /// </summary>
            public SharedFolderMemberError Value { get; private set; }

            #region Encoder class

            /// <summary>
            /// <para>Encoder for  <see cref="MemberError" />.</para>
            /// </summary>
            private class MemberErrorEncoder : enc.StructEncoder<MemberError>
            {
                /// <summary>
                /// <para>Encode fields of given value.</para>
                /// </summary>
                /// <param name="value">The value.</param>
                /// <param name="writer">The writer.</param>
                public override void EncodeFields(MemberError value, enc.IJsonWriter writer)
                {
                    WriteProperty("member_error", value.Value, writer, global::Dropbox.Api.Sharing.SharedFolderMemberError.Encoder);
                }
            }

            #endregion

            #region Decoder class

            /// <summary>
            /// <para>Decoder for  <see cref="MemberError" />.</para>
            /// </summary>
            private class MemberErrorDecoder : enc.StructDecoder<MemberError>
            {
                /// <summary>
                /// <para>Create a new instance of type <see cref="MemberError" />.</para>
                /// </summary>
                /// <returns>The struct instance.</returns>
                protected override MemberError Create()
                {
                    return new MemberError();
                }

                /// <summary>
                /// <para>Set given field.</para>
                /// </summary>
                /// <param name="value">The field value.</param>
                /// <param name="fieldName">The field name.</param>
                /// <param name="reader">The json reader.</param>
                protected override void SetField(MemberError value, string fieldName, enc.IJsonReader reader)
                {
                    switch (fieldName)
                    {
                        case "member_error":
                            value.Value = global::Dropbox.Api.Sharing.SharedFolderMemberError.Decoder.Decode(reader);
                            break;
                        default:
                            reader.Skip();
                            break;
                    }
                }
            }

            #endregion
        }

        /// <summary>
        /// <para>The target user is the owner of the shared folder. You can't remove this user
        /// until ownership has been transferred to another member.</para>
        /// </summary>
        public sealed class FolderOwner : RemoveFolderMemberError
        {
            #pragma warning disable 108

            /// <summary>
            /// <para>The encoder instance.</para>
            /// </summary>
            internal static enc.StructEncoder<FolderOwner> Encoder = new FolderOwnerEncoder();

            /// <summary>
            /// <para>The decoder instance.</para>
            /// </summary>
            internal static enc.StructDecoder<FolderOwner> Decoder = new FolderOwnerDecoder();

            /// <summary>
            /// <para>Initializes a new instance of the <see cref="FolderOwner" />
            /// class.</para>
            /// </summary>
            private FolderOwner()
            {
            }

            /// <summary>
            /// <para>A singleton instance of FolderOwner</para>
            /// </summary>
            public static readonly FolderOwner Instance = new FolderOwner();

            #region Encoder class

            /// <summary>
            /// <para>Encoder for  <see cref="FolderOwner" />.</para>
            /// </summary>
            private class FolderOwnerEncoder : enc.StructEncoder<FolderOwner>
            {
                /// <summary>
                /// <para>Encode fields of given value.</para>
                /// </summary>
                /// <param name="value">The value.</param>
                /// <param name="writer">The writer.</param>
                public override void EncodeFields(FolderOwner value, enc.IJsonWriter writer)
                {
                }
            }

            #endregion

            #region Decoder class

            /// <summary>
            /// <para>Decoder for  <see cref="FolderOwner" />.</para>
            /// </summary>
            private class FolderOwnerDecoder : enc.StructDecoder<FolderOwner>
            {
                /// <summary>
                /// <para>Create a new instance of type <see cref="FolderOwner" />.</para>
                /// </summary>
                /// <returns>The struct instance.</returns>
                protected override FolderOwner Create()
                {
                    return FolderOwner.Instance;
                }

            }

            #endregion
        }

        /// <summary>
        /// <para>The target user has access to the shared folder via a group.</para>
        /// </summary>
        public sealed class GroupAccess : RemoveFolderMemberError
        {
            #pragma warning disable 108

            /// <summary>
            /// <para>The encoder instance.</para>
            /// </summary>
            internal static enc.StructEncoder<GroupAccess> Encoder = new GroupAccessEncoder();

            /// <summary>
            /// <para>The decoder instance.</para>
            /// </summary>
            internal static enc.StructDecoder<GroupAccess> Decoder = new GroupAccessDecoder();

            /// <summary>
            /// <para>Initializes a new instance of the <see cref="GroupAccess" />
            /// class.</para>
            /// </summary>
            private GroupAccess()
            {
            }

            /// <summary>
            /// <para>A singleton instance of GroupAccess</para>
            /// </summary>
            public static readonly GroupAccess Instance = new GroupAccess();

            #region Encoder class

            /// <summary>
            /// <para>Encoder for  <see cref="GroupAccess" />.</para>
            /// </summary>
            private class GroupAccessEncoder : enc.StructEncoder<GroupAccess>
            {
                /// <summary>
                /// <para>Encode fields of given value.</para>
                /// </summary>
                /// <param name="value">The value.</param>
                /// <param name="writer">The writer.</param>
                public override void EncodeFields(GroupAccess value, enc.IJsonWriter writer)
                {
                }
            }

            #endregion

            #region Decoder class

            /// <summary>
            /// <para>Decoder for  <see cref="GroupAccess" />.</para>
            /// </summary>
            private class GroupAccessDecoder : enc.StructDecoder<GroupAccess>
            {
                /// <summary>
                /// <para>Create a new instance of type <see cref="GroupAccess" />.</para>
                /// </summary>
                /// <returns>The struct instance.</returns>
                protected override GroupAccess Create()
                {
                    return GroupAccess.Instance;
                }

            }

            #endregion
        }

        /// <summary>
        /// <para>This action cannot be performed on a team shared folder.</para>
        /// </summary>
        public sealed class TeamFolder : RemoveFolderMemberError
        {
            #pragma warning disable 108

            /// <summary>
            /// <para>The encoder instance.</para>
            /// </summary>
            internal static enc.StructEncoder<TeamFolder> Encoder = new TeamFolderEncoder();

            /// <summary>
            /// <para>The decoder instance.</para>
            /// </summary>
            internal static enc.StructDecoder<TeamFolder> Decoder = new TeamFolderDecoder();

            /// <summary>
            /// <para>Initializes a new instance of the <see cref="TeamFolder" /> class.</para>
            /// </summary>
            private TeamFolder()
            {
            }

            /// <summary>
            /// <para>A singleton instance of TeamFolder</para>
            /// </summary>
            public static readonly TeamFolder Instance = new TeamFolder();

            #region Encoder class

            /// <summary>
            /// <para>Encoder for  <see cref="TeamFolder" />.</para>
            /// </summary>
            private class TeamFolderEncoder : enc.StructEncoder<TeamFolder>
            {
                /// <summary>
                /// <para>Encode fields of given value.</para>
                /// </summary>
                /// <param name="value">The value.</param>
                /// <param name="writer">The writer.</param>
                public override void EncodeFields(TeamFolder value, enc.IJsonWriter writer)
                {
                }
            }

            #endregion

            #region Decoder class

            /// <summary>
            /// <para>Decoder for  <see cref="TeamFolder" />.</para>
            /// </summary>
            private class TeamFolderDecoder : enc.StructDecoder<TeamFolder>
            {
                /// <summary>
                /// <para>Create a new instance of type <see cref="TeamFolder" />.</para>
                /// </summary>
                /// <returns>The struct instance.</returns>
                protected override TeamFolder Create()
                {
                    return TeamFolder.Instance;
                }

            }

            #endregion
        }

        /// <summary>
        /// <para>The current user does not have permission to perform this action.</para>
        /// </summary>
        public sealed class NoPermission : RemoveFolderMemberError
        {
            #pragma warning disable 108

            /// <summary>
            /// <para>The encoder instance.</para>
            /// </summary>
            internal static enc.StructEncoder<NoPermission> Encoder = new NoPermissionEncoder();

            /// <summary>
            /// <para>The decoder instance.</para>
            /// </summary>
            internal static enc.StructDecoder<NoPermission> Decoder = new NoPermissionDecoder();

            /// <summary>
            /// <para>Initializes a new instance of the <see cref="NoPermission" />
            /// class.</para>
            /// </summary>
            private NoPermission()
            {
            }

            /// <summary>
            /// <para>A singleton instance of NoPermission</para>
            /// </summary>
            public static readonly NoPermission Instance = new NoPermission();

            #region Encoder class

            /// <summary>
            /// <para>Encoder for  <see cref="NoPermission" />.</para>
            /// </summary>
            private class NoPermissionEncoder : enc.StructEncoder<NoPermission>
            {
                /// <summary>
                /// <para>Encode fields of given value.</para>
                /// </summary>
                /// <param name="value">The value.</param>
                /// <param name="writer">The writer.</param>
                public override void EncodeFields(NoPermission value, enc.IJsonWriter writer)
                {
                }
            }

            #endregion

            #region Decoder class

            /// <summary>
            /// <para>Decoder for  <see cref="NoPermission" />.</para>
            /// </summary>
            private class NoPermissionDecoder : enc.StructDecoder<NoPermission>
            {
                /// <summary>
                /// <para>Create a new instance of type <see cref="NoPermission" />.</para>
                /// </summary>
                /// <returns>The struct instance.</returns>
                protected override NoPermission Create()
                {
                    return NoPermission.Instance;
                }

            }

            #endregion
        }

        /// <summary>
        /// <para>This shared folder has too many files for leaving a copy. You can still
        /// remove this user without leaving a copy.</para>
        /// </summary>
        public sealed class TooManyFiles : RemoveFolderMemberError
        {
            #pragma warning disable 108

            /// <summary>
            /// <para>The encoder instance.</para>
            /// </summary>
            internal static enc.StructEncoder<TooManyFiles> Encoder = new TooManyFilesEncoder();

            /// <summary>
            /// <para>The decoder instance.</para>
            /// </summary>
            internal static enc.StructDecoder<TooManyFiles> Decoder = new TooManyFilesDecoder();

            /// <summary>
            /// <para>Initializes a new instance of the <see cref="TooManyFiles" />
            /// class.</para>
            /// </summary>
            private TooManyFiles()
            {
            }

            /// <summary>
            /// <para>A singleton instance of TooManyFiles</para>
            /// </summary>
            public static readonly TooManyFiles Instance = new TooManyFiles();

            #region Encoder class

            /// <summary>
            /// <para>Encoder for  <see cref="TooManyFiles" />.</para>
            /// </summary>
            private class TooManyFilesEncoder : enc.StructEncoder<TooManyFiles>
            {
                /// <summary>
                /// <para>Encode fields of given value.</para>
                /// </summary>
                /// <param name="value">The value.</param>
                /// <param name="writer">The writer.</param>
                public override void EncodeFields(TooManyFiles value, enc.IJsonWriter writer)
                {
                }
            }

            #endregion

            #region Decoder class

            /// <summary>
            /// <para>Decoder for  <see cref="TooManyFiles" />.</para>
            /// </summary>
            private class TooManyFilesDecoder : enc.StructDecoder<TooManyFiles>
            {
                /// <summary>
                /// <para>Create a new instance of type <see cref="TooManyFiles" />.</para>
                /// </summary>
                /// <returns>The struct instance.</returns>
                protected override TooManyFiles Create()
                {
                    return TooManyFiles.Instance;
                }

            }

            #endregion
        }

        /// <summary>
        /// <para>The other object</para>
        /// </summary>
        public sealed class Other : RemoveFolderMemberError
        {
            #pragma warning disable 108

            /// <summary>
            /// <para>The encoder instance.</para>
            /// </summary>
            internal static enc.StructEncoder<Other> Encoder = new OtherEncoder();

            /// <summary>
            /// <para>The decoder instance.</para>
            /// </summary>
            internal static enc.StructDecoder<Other> Decoder = new OtherDecoder();

            /// <summary>
            /// <para>Initializes a new instance of the <see cref="Other" /> class.</para>
            /// </summary>
            private Other()
            {
            }

            /// <summary>
            /// <para>A singleton instance of Other</para>
            /// </summary>
            public static readonly Other Instance = new Other();

            #region Encoder class

            /// <summary>
            /// <para>Encoder for  <see cref="Other" />.</para>
            /// </summary>
            private class OtherEncoder : enc.StructEncoder<Other>
            {
                /// <summary>
                /// <para>Encode fields of given value.</para>
                /// </summary>
                /// <param name="value">The value.</param>
                /// <param name="writer">The writer.</param>
                public override void EncodeFields(Other value, enc.IJsonWriter writer)
                {
                }
            }

            #endregion

            #region Decoder class

            /// <summary>
            /// <para>Decoder for  <see cref="Other" />.</para>
            /// </summary>
            private class OtherDecoder : enc.StructDecoder<Other>
            {
                /// <summary>
                /// <para>Create a new instance of type <see cref="Other" />.</para>
                /// </summary>
                /// <returns>The struct instance.</returns>
                protected override Other Create()
                {
                    return Other.Instance;
                }

            }

            #endregion
        }
    }
}


text:
function [Sigma] = SigmaUpdate(Sigma,pos,Alpsup,w0,C,Xapp,yapp,option,pow,verbose)
%SIGMAUPDATE Update Sigma value
%     [SIGMA] = SIGMAUPDATE(SIGMA,POS,ALPSUP,W0,C,XAPP,YAPP,OPTION,POW,VERBOSE)
%     updates the kernel scale parameters SIGMA
%     based on
%     - the current Sigma value SIGMA;
%     - the SVM parameters POS,ALPSUP,W0;
%     - the SVM hyper-parameters C and POW
%     - the learning data set XAPP,YAPP
%     - the update option OPTION: ['wbfixed','wfixed','lbfixed','lfixed','lupdate]
%
%     VERBOSE = [0,1] sets the verbosity level during the update
%

%       uses functions COST*FIXED, GRAD*FIXED
%       27/01/03 Y. Grandvalet

%------------------------------------------------------------------------------%
% Initialize
%------------------------------------------------------------------------------%

d = length(Sigma);
gold = (sqrt(5)+1)/2 ;

SigmaInit = Sigma ;
SigmaNew  = SigmaInit ;
descold = zeros(1,d);

% Initial cost and gradient

switch option
case 'wbfixed'
        CostNew = costwbfixed(0,descold,SigmaNew,pos,Alpsup,w0,C,SigmaInit,Xapp,yapp,pow) ;
case 'wfixed'
        CostNew = costwfixed(0,descold,SigmaNew,pos,Alpsup,C,SigmaInit,Xapp,yapp,pow) ;
case 'lbfixed'
        CostNew = costlbfixed(0,descold,SigmaNew,pos,Alpsup,w0,C,Xapp,yapp,pow) ;
case {'lfixed','lupdate'}
        CostNew = costlfixed(0,descold,SigmaNew,pos,Alpsup,C,Xapp,yapp,pow) ;
otherwise
        error('Unkwown option in SigmaUpdate')
end;

switch option
case 'wbfixed'
        GradNew = gradwbfixed(SigmaNew,pos,Alpsup,w0,C,Xapp,yapp,SigmaInit,pow) ;
case 'wfixed'
        GradNew = gradwfixed(SigmaNew,pos,Alpsup,C,Xapp,yapp,SigmaInit,pow) ;
case 'lbfixed'
        GradNew = gradlbfixed(SigmaNew,pos,Alpsup,w0,C,Xapp,yapp,pow) ;
case {'lfixed','lupdate'}
        GradNew = gradlfixed(SigmaNew,pos,Alpsup,C,Xapp,yapp,pow) ;
end;
% reduced gradient, descent direction
[val,coord] = max(SigmaNew) ;
GradNew = GradNew - GradNew(coord) ;
desc = - GradNew.* ( (SigmaNew>0) | (GradNew<0) ) ;
desc(coord) = - sum(desc);  % NB:  GradNew(coord) = 0

if verbose > 0,
  fprintf(1,'Sigma init, Cost init ');
  fprintf(1,'%9.2e ',[SigmaNew  CostNew]);
  fprintf(1,'\n');
end;

loop = any(desc~=0);
while loop,
   SigmaOld = SigmaNew;
   CostOld  = CostNew;
   GradOld  = GradNew;
   NormGrad = GradNew*GradNew';
   if sqrt(NormGrad)<eps;
      loop = 0;
      fprintf(1,'No more descent direction. Sigma update terminated.\n')
   else
      % Compute optimal stepsize
      stepmin  = 0;
      costmin  = CostOld ;
      costmax  = 0 ;
      % maximum stepsize
      ind = find(desc<0);
      stepmax = min(-(SigmaNew(ind).^pow)./desc(ind));
      deltmax = stepmax;
      while costmax<costmin;
         switch option
         case 'wbfixed'
               costmax = costwbfixed(stepmax,desc,SigmaNew,pos,Alpsup,w0,C,SigmaInit,Xapp,yapp,pow) ;
         case 'wfixed'
               costmax = costwfixed(stepmax,desc,SigmaNew,pos,Alpsup,C,SigmaInit,Xapp,yapp,pow) ;
         case 'lbfixed'
               costmax = costlbfixed(stepmax,desc,SigmaNew,pos,Alpsup,w0,C,Xapp,yapp,pow) ;
         case {'lfixed','lupdate'}
               costmax = costlfixed(stepmax,desc,SigmaNew,pos,Alpsup,C,Xapp,yapp,pow) ;
         end;
         if costmax<costmin
            costmin = costmax;
            SigmaP  = SigmaNew.^pow + stepmax * desc;
            SigmaNew  = abs(real(SigmaP.^(1/pow)));
	    % project descent direction in the new admissible cone
            desc = desc .* ( (SigmaNew>0) | (desc>0) ) ;
            desc(coord) = - sum(desc([[1:coord-1] [coord+1:end]]));
            ind = find(desc<0);
            if ~isempty(ind)
               stepmax = min(-(SigmaNew(ind).^pow)./desc(ind));
               deltmax = stepmax;
               costmax = 0;
            else
               stepmax = 0;
               deltmax = 0;
            end;
         end;
      end;
      % update Lagrange multipliers ?
      if strcmp(option,'lupdate')
         [deltAlp,stepAlp] = LagrangeUpdate(desc,SigmaNew,Xapp(pos,:),Alpsup,C,pow);
         costmax = costlfixed(stepmax,desc,SigmaNew,pos,Alpsup+min(stepmax,stepAlp)*deltAlp,C,Xapp,yapp,pow) ;
      end;
      Step = [stepmin stepmax];
      Cost = [costmin costmax];
      [val,coord] = min(Cost);
      % optimization of stepsize by golden search
      while (stepmax-stepmin)>1e-3*(deltmax);
         stepmedr = stepmin+(stepmax-stepmin)/gold;
         stepmedl = stepmin+(stepmedr-stepmin)/gold;
         switch option
         case 'wbfixed'
              costmedr = costwbfixed(stepmedr,desc,SigmaNew,pos,Alpsup,w0,C,SigmaInit,Xapp,yapp,pow) ;
	      costmedl = costwbfixed(stepmedl,desc,SigmaNew,pos,Alpsup,w0,C,SigmaInit,Xapp,yapp,pow) ;
         case 'wfixed'
              costmedr = costwfixed(stepmedr,desc,SigmaNew,pos,Alpsup,C,SigmaInit,Xapp,yapp,pow) ;
              costmedl = costwfixed(stepmedl,desc,SigmaNew,pos,Alpsup,C,SigmaInit,Xapp,yapp,pow) ;
         case 'lbfixed'
               costmedr = costlbfixed(stepmedr,desc,SigmaNew,pos,Alpsup,w0,C,Xapp,yapp,pow) ;
               costmedl = costlbfixed(stepmedl,desc,SigmaNew,pos,Alpsup,w0,C,Xapp,yapp,pow) ;
         case 'lfixed'
               costmedr = costlfixed(stepmedr,desc,SigmaNew,pos,Alpsup,C,Xapp,yapp,pow) ;
               costmedl = costlfixed(stepmedl,desc,SigmaNew,pos,Alpsup,C,Xapp,yapp,pow) ;
         case 'lupdate'
              costmedr = costlfixed(stepmedr,desc,SigmaNew,pos,Alpsup+min(stepmedr,stepAlp)*deltAlp,C,Xapp,yapp,pow) ;
              costmedl = costlfixed(stepmedl,desc,SigmaNew,pos,Alpsup+min(stepmedl,stepAlp)*deltAlp,C,Xapp,yapp,pow) ;
         end;
         Step = [stepmin stepmedl stepmedr stepmax];
         Cost = [costmin costmedl costmedr costmax];
         [val,coord] = min(Cost);
         switch coord
         case 1
              stepmax = stepmedl;
              costmax = costmedl;
         case 2
              stepmax = stepmedr;
              costmax = costmedr;
         case 3
              stepmin = stepmedl;
              costmin = costmedl;
         case 4
              stepmin = stepmedr;
              costmin = costmedr;
         end;
      end;
      CostNew = Cost(coord) ;
      step = Step(coord) ;
      % Sigma update
      if CostNew < CostOld ;
         SigmaP = SigmaNew.^pow + step * desc;
         SigmaNew  = abs(real(SigmaP.^(1/pow)));
         if verbose > 0,
            fprintf(1,'Sigma new, cost new ');
            fprintf(1,'%9.2e ',[SigmaNew CostNew]);
            fprintf(1,'\n');
         end;
         switch option
         case 'wbfixed'
              GradNew = gradwbfixed(SigmaNew,pos,Alpsup,w0,C,Xapp,yapp,SigmaInit,pow) ;
         case 'wfixed'
              GradNew = gradwfixed(SigmaNew,pos,Alpsup,C,Xapp,yapp,SigmaInit,pow) ;
         case 'lbfixed'
              GradNew = gradlbfixed(SigmaNew,pos,Alpsup,w0,C,Xapp,yapp,pow) ;
         case {'lfixed','lupdate'}
              GradNew = gradlfixed(SigmaNew,pos,Alpsup,C,Xapp,yapp,pow) ;
         end;
         [val,coord] = max(SigmaNew) ;
         GradNew = GradNew - GradNew(coord) ;
         desc = ( ((GradNew - GradOld)*(GradNew)')/NormGrad )*desc - GradNew ;
         desc = desc .* ( (SigmaNew>0) | (desc>0) ) ;
         desc(coord) = - sum(desc([[1:coord-1] [coord+1:d]]));
         if all(desc==0),
            % restart from Gradient if no admissible descent direction
            desc = -GradNew .* ( (SigmaNew>0) | (GradNew<0) ) ;
            desc(coord) = - sum(desc([[1:coord-1] [coord+1:d]]));
            if all(desc==0)
               SigmaOld = SigmaNew;
            end;
         end;
      elseif (verbose > 0) & all(SigmaNew==SigmaInit),
         disp('No sigma update, step opt. = 0 ')
      end;
      loop = max(abs(SigmaNew - SigmaOld)./(mean(SigmaOld)+SigmaOld))>1e-3;
   end;
end;
Sigma = SigmaNew ;