docstr: Compute PSI(x,label).
docstr_tok: ["Compute","PSI","(","x",",","label",")","."]
code: def make_psi(self, x, label):
      """Compute PSI(x,label)."""
      # All we are doing here is taking x, which is a 3 dimensional sample
      # vector in this example program, and putting it into one of 3 places in
      # a 9 dimensional PSI vector, which we then return.  So this function
      # returns PSI(x,label).  To see why we setup PSI like this, recall how
      # predict_label() works.  It takes in a 9 dimensional weight vector and
      # breaks the vector into 3 pieces.  Each piece then defines a different
      # classifier and we use them in a one-vs-all manner to predict the
      # label.  So now that we are in the structural SVM code we have to
      # define the PSI vector to correspond to this usage.  That is, we need
      # to setup PSI so that argmax_y dot(weights,PSI(x,y)) ==
      # predict_label(weights,x).  This is how we tell the structural SVM
      # solver what kind of problem we are trying to solve.
      #
      # It's worth emphasizing that the single biggest step in using a
      # structural SVM is deciding how you want to represent PSI(x,label).  It
      # is always a vector, but deciding what to put into it to solve your
      # problem is often not a trivial task. Part of the difficulty is that
      # you need an efficient method for finding the label that makes
      # dot(w,PSI(x,label)) the biggest.  Sometimes this is easy, but often
      # finding the max scoring label turns into a difficult combinatorial
      # optimization problem.  So you need to pick a PSI that doesn't make the
      # label maximization step intractable but also still well models your
      # problem.
      #
      # Create a dense vector object (note that you can also use unsorted
      # sparse vectors (i.e.  dlib.sparse_vector objects) to represent your
      # PSI vector.  This is useful if you have very high dimensional PSI
      # vectors that are mostly zeros.  In the context of this example, you
      # would simply return a dlib.sparse_vector at the end of make_psi() and
      # the rest of the example would still work properly. ).
      psi = dlib.vector()
      # Set it to have 9 dimensions.  Note that the elements of the vector
      # are 0 initialized.
      psi.resize(self.num_dimensions)
      dims = len(x)
      if label == 0:
          for i in range(0, dims):
              psi[i] = x[i]
      elif label == 1:
          for i in range(dims, 2 * dims):
              psi[i] = x[i - dims]
      else:  # the label must be 2
          for i in range(2 * dims, 3 * dims):
              psi[i] = x[i - 2 * dims]
      return psi
  
file_path: dlib/python_examples/svm_struct.py
imports: import dlib
label_desc: Use image node_id 2 for calling the ThreeClassClassifierProblem obj's underlying member method code with example usage: obj.make_psi(x, label) and returns: psi